int maior=0;
int maior2=0;
int aux=0;
for (int i=0; i<4; i++){
aux=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero "+(i+1)));
if (aux > maior){
maior2 = maior;
maior = aux;
}else if (aux > maior2){
maior2 = aux;
}
}
System.out.println("Maiores # são: "+maior+" e "+maior2);
[quote=“eltonk”]
int maior=0;
int maior2=0;
int aux=0;
for (int i=0; i<4; i++){
aux=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero "+(i+1)));
if (aux > maior){
maior2 = maior;
maior = aux;
}else if (aux > maior2){
maior2 = aux;
}
}
System.out.println("Maiores # são: "+maior+" e "+maior2);
[/quote]
Desse jeito não vai funcionar se todos os números forem negativos:
int maior=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero 1"));
int maior2=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero 2"));
int aux;
if (maior2 > maior){
aux = maior;
maior = maior2;
maior2 = aux;
}
for (int i=2; i<4; i++){
aux=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero "+(i+1)));
if (aux > maior){
maior2 = maior;
maior = aux;
}else if (aux > maior2){
maior2 = aux;
}
}