Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ordenacao1;
- import java.util.Scanner;
- /**
- *
- * @author alunoead
- */
- public class Ordenacao1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int x[] = new int [5];
- int n, i, aux;
- Scanner sc1 = new Scanner(System.in);
- //carregando os numeros no vetor
- for(i = 0; i <= 4; i++)
- {
- System.out.println("Digite o "+(i+1)+"° número: ");
- x[i] = sc1.nextInt();
- }
- //ordenando de forma crescente
- //laço com quantidade de elementos do vetor
- for(n=1; n <= 5; n++)
- {
- for(i = 0; i <= 3; i++)
- {
- if (x[i] > x[i+1])
- {aux = x[i];
- x[i] = x[i+1];
- x[i+1] = aux;
- }
- }
- }
- //mostrando o vetor ordenado
- for(i=0; i <= 4; i++)
- {
- System.out.println((i+1)+"° número: "+x[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement