import java.util.*;
public class HelloWorld {
public static void main(String[] args){
int[] scores = new int[]{89,-23,64,119,91,52,73};
int[] grade = new int[3];
HelloWorld hehe = new HelloWorld();
hehe.qsort(scores,grade);
System.out.println("考试成绩的前三名为:");
System.out.println(grade[0]);
System.out.println(grade[1]);
System.out.println(grade[2]);
}
private void qsort(int[] scores, int[] grade) {
// TODO Auto-generated method stub
int count = 0;
Arrays.sort(scores);
for(int i=scores.length-1;i>=0;--i){
if (scores[i]>=0&&scores[i]<=100) {
if (count>=3) {
break;
}
grade[count++]=scores[i];
}
}
}
}
你的代码在 qsort的for循环多走了一遍,你可以将 grade[count++]=scores[i]; 放在 if语句上面