Hacer un programa o algoritmo que si se ingresan 5 notas de un alumno, publicar las 2 peores notas
Solución
- Entrada: 15, 10, 13, 8,19
- Salida: 10, 8
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int u=0,tem;
int Nota[]=new int[5];
for(int i=0;i<5;i++){
System.out.println("Ingresa Nota");
Nota[i]=sc.nextInt();
}
while(u!=4){
u=0;
for(int k=0;k<4;k++){
if(Nota[k]<=Nota[k+1]){
u++;
}else{
tem=Nota[k];
Nota[k]=Nota[k+1];
Nota[k+1]=tem;
}
}
}
System.out.println("Las 2 peores notas obtenidas son: " +
(Nota[0]) + " y " + (Nota[1]));
}
}
0 comentarios:
Publicar un comentario