
un favor ayundeme no me sale para mostrar los dos numeros mayores
Publicado por manuel (7 intervenciones) el 01/07/2017 00:36:16

Valora esta pregunta


0
Scanner sc=new Scanner(System.in);
System.out.println("Introduzca numeros hasta introducir 0");
int n,cont=0,mayor=0,mayorSegundo=0;
n=sc.nextInt();
while(n>0){
cont++;
if(n>mayor){
mayorSegundo=mayor;
mayor=n;
}
if(n<mayor&&n>mayorSegundo){
mayorSegundo=n;
}
n=sc.nextInt();
}
System.out.println("El mayor es "+mayor+" el segundo mayor "+mayorSegundo+" los numeros introducidos "+cont );
}