public class HelloWord {
//完成 main 方法
public static void main(String[] args) {
int[] score={89,-23,64,91,119,52,73};
HelloWord he=new HelloWord();
he.scoreSort(score);
}
//定义方法完成成绩排序并输出前三名的功能
public void scoreSort(int[] scores){
System.out.println("考试成绩的前三名为:");
Arrays.sort(scores);
int count=1;
for(int i=scores.length-1;i>=0;i--){
count++;
System.out.println(scores[i]);
if(scores[i]<0||scores[i]>100){
continue;
}
if(count>3){
break;
}
}
}
}结果是
考试成绩的前三名为:
119
91
89
找到原因了,是位置写错了
public void scoreSort(int[] scores){
System.out.println("考试成绩的前三名为:");
Arrays.sort(scores);
int count=1;
for(int i=scores.length-1;i>=0;i--){
//count++;
//System.out.println(scores[i]);
if(scores[i]<0||scores[i]>100){
continue;
}
count++;
System.out.println(scores[i]);
if(count>3){
break;
}
}
}