Hacer un programa o algoritmo que permita mostrar alumnos ordenados por mayor puntaje de promedio.
Solución
- Entrada: Juan 12, lucia 10, alex 16,Sandra 14
- Salida: alex16,Sandra 14,juan 12,lucia 10
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String cad="",aux,n;
int w=0,cont=0,tem,p;
System.out.println("ingresa la cantidad de alumnos a ingresar");
int t = sc.nextInt();
String []Nom= new String[t];
int []Prom= new int[t];
for(int i=0;i<t;i++){
Nom[i]="";
Prom[i]=0;
}
while(t>cont){
System.out.println("Ingresa nombre");
n=sc.next();
Nom[cont]=n;
System.out.println("Ingresa nota");
p= sc.nextInt();
Prom[cont]=p;
cont++;
}
while(w!=(t-1)){
w=0;
for(int k=0;k<(t-1);k++){
if(Prom[k]>=Prom[k+1]){
w++;
}else{
tem=Prom[k];
Prom[k]=Prom[k+1];
Prom[k+1]=tem;
aux=Nom[k];
Nom[k]=Nom[k+1];
Nom[k+1]=aux;
}
}
}
for(int j=0;j<t;j++){
cad=cad+"Nombre: "+Nom[j]+" Nota: "+Prom[j]+"\n";
}
System.out.println(cad);
}
}
0 comentarios:
Publicar un comentario