求大神指错
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
HelloWorld hello =new HelloWorld();
int[] scores={89,-23,64,91,119,52,73};
System.out.println("前三名成绩:");
hello.print(scores);
}
//定义方法完成成绩排序并输出前三名的功能
public void print(int [] score){
Arrays.sort(score);
int count=0;
for(int i=score.length-1;i>=0;i++){
if(score[i]>=0&&score[i]<=100){
System.out.println(score[i]);
count++;
}
else{
continue;
}
if(count>3){
break;
}
}
}
}
错误是这样的:
前三名成绩:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at HelloWorld.print(HelloWorld.java:23)
at HelloWorld.main(HelloWorld.java:9)