intmaior=0;intmaior2=0;intaux=0;for(inti=0;i<4;i++){aux=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero "+(i+1)));if(aux>maior){maior2=maior;maior=aux;}elseif(aux>maior2){maior2=aux;}}System.out.println("Maiores # são: "+maior+" e "+maior2);
F
FelipePJ
“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);
Desse jeito não vai funcionar se todos os números forem negativos:
intmaior=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero 1"));intmaior2=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero 2"));intaux;if(maior2>maior){
aux=maior;maior=maior2;maior2=aux;
}
for(inti=2; i<4; i++){aux=Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero "+(i+1)));if(aux>maior){
maior2=maior;maior=aux;}elseif(aux>maior2){
maior2=aux;}
}