I need to put 5 pesos in order from the smallest to the largest. Defining numbers first, for example: int vet [] = {3,4,2,8,7,1}; it runs right, but I need to do it this way: int vet [] = new int [5]; this way he is only taking 3 numbers as shown in the image. follow the code:
intvet[]=newint[5];intaux;booleancontrole;for(inti=0;i<vet.length;i++){vet[i]=Integer.parseInt(JOptionPane.showInputDialog("Digite o peso: "));
controle = true;
for(int j = 0; j < (vet.length -1); j++) {
if(vet[j] > vet[j+1]) {
aux = vet[j];
vet[j] = vet[j + 1];
vet[j + 1] = aux;
controle = false;
}
}
if(controle) {
break;
}
}
for(int i = 0; i < vet.length; i++) {
System.out.println(vet[i] + "");
}