1
I need to register five names and their heights, then show them all in ascending order. The problem is I can only put the heights in order, the names are in the order I typed. And also I’m not able to use the double in place of the int for the height, because of the error. If there’s something really wrong, it’s because I’m still new.
public static void main(String args[]) {
int numero = Integer.parseInt(JOptionPane.showInputDialog("Digite o número de pessoas a ser cadastrado "));
String vet[] = new String[numero];
int altura[] = new int[5];
int aux;
for (int i = 0; i < vet.length; i++) {
vet[i] = JOptionPane.showInputDialog("Digite o nome: ", null);
altura[i] = Integer.parseInt(JOptionPane.showInputDialog("Digite a altura: ", null));
}
for (int i = 0; i < altura.length; i++) {
for (int j = 0; j < (altura.length); j++) {
if (altura[i] < altura[j]) {
aux = altura[i];
altura[i] = altura[j];
altura[j] = aux;
}
}
}
for (int i = 0; i < altura.length; i++) {
System.out.println("Nome " + (i+1) + "º " + vet[i] + altura[i] + "");
}
}
Thank you Carlos heuberger, I used aux2 in the code and it worked!
– Lunnie