import java.util.Scanner;
public class P {
public static void main(String[] args) {
final String NewLine=System.getProperty("line.separator");
Scanner sc=new Scanner(System.in);
boolean swap=true;
String[] names;
int[] scores;
int sorted=0,n,s;
String str;
System.out.println("请输入学生的人数:");
n=sc.nextInt();
names=new String[n];
scores=new int[n];
for(int i=0;i<n;i++) {
System.out.printf("请输入第%d个学生的姓名 成绩:",i+1);
names[i]=sc.next();
scores[i]=sc.nextInt();
}
//冒泡排序
while(swap) {
swap=false;
for(int i=0;i<scores.length-1-sorted;i++) {
if(scores[i]<scores[i+1]) {
s=scores[i];
scores[i]=scores[i+1];
scores[i+1]=s;
str=names[i];
names[i]=names[i+1];
names[i+1]=str;
swap=true;
}
}
sorted++;
}
System.out.println("按成绩降序排序后,学生的信息如下:");
for(int i=0;i<n;i++) {
System.out.printf("%s\t%d%s",names[i],scores[i],NewLine);
}
sc.close();
}
}
追答
本回答被网友采纳