import java.util.Arrays;
public class Demo{
public static void main(String[] args) {
int[] scores= {89,-23,-64,91,119,52,73};
Demo abc=new Demo();
abc.hello(scores);
}
public void hello(int[] scores){
Arrays.sort(scores);
for(int i=scores.length-1,b=0;i>=0&&b<3;++i,++b) {
if(scores[i]>100||scores[i]<0) {
continue;
}
else {
System.out.println(scores[i]);
}
}
}
}
for循环里应该是 --i,因为前面i已经等于scores.length-1(下标最大值)了,++i的话就会抛出数组下标越界异常(ArrayIndexOutOfBoundsException)