请问 这样写错在哪里?谢谢!
package com.Java;
import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args) {
int[] scores = {89 , -23 , 64 , 91 , 119 , 52 , 73};
System.out.println("成绩前三名为:");
HelloWorld hello = new HelloWorld();
hello.sortAndPrint(scores);
}
public void sortAndPrint(int[] scores){
Arrays.sort(scores);
int num=0;
for (int i=scores.length ;i>=0;i--){
if (scores[i]>0 && scores[i]<=100){
System.out.println(scores[i]);
num++;
} else {
continue;
}
if (num==3){break;}
}
}
}
运行结果
成绩前三名为:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at com.Java.HelloWorld.sortAndPrint(HelloWorld.java:27)
at com.Java.HelloWorld.main(HelloWorld.java:15)