System.out.println(“姓名\t学号\t成绩”);
for (int i = 0; i < size; i++) {
System.out.println(stuNames[i]+"\t"+stuNOs[i]+"\t"+ ( stuScores[i] == -1?“无成绩” : stuScores[i]));
}
String[] newstu = new String[size];
String[] newno = new String[size];
int[] newsc = new int[size];
System.arraycopy(stuNames, 0, newstu, 0, size );
System.arraycopy(stuNOs, 0, newno, 0, size );
System.arraycopy(stuScores, 0, newsc, 0, size );
for (int x = 0; x < newstu.length - 1; x++) {
int maxIndex = 0;
for (int y = 0; y < newstu.length - x -1; y++) {
if(newsc[maxIndex] < newsc[y+1]) {
maxIndex = y + 1;
}
}
int temp = newsc[maxIndex];
newsc[maxIndex] = newsc[newsc.length - x - 1];
newsc[newsc.length - x - 1] = temp;
}
System.out.println(“姓名\t学号\t成绩”);
for (int i = 0; i < size; i++) {
System.out.println(newstu[i]+"\t"+newno[i]+"\t"+ newsc[i]);
}
java 入门小白初级 怎么用冒泡方法对成绩、学号、姓名进行排序
最新推荐文章于 2023-06-11 14:08:58 发布