long_l
2017-07-15 21:59
package a22;
import java.util.Arrays;
public class Lian9 {
public static void main(String[] args) {
int []scores= {89 , -23 , 64 , 91 , 119 , 52 , 73};
Lian9 hello=new Lian9();
System.out.println("考试成绩的前3名为:");
hello.text(scores);
}
public void text(int [] scores) {
Arrays.sort(scores);
int num=0;
for(int i=scores.length;i>=0;i--) {
if(scores[i]>=0&&scores[i]<=100 ) {
num++;
}
System.out.println(scores[i]);
if(num>2) {
break;
}
}
}
}运行结果是这样的:
考试成绩的前3名为:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at a22.Lian9.text(Lian9.java:16)
at a22.Lian9.main(Lian9.java:9)
已解决
Java入门第一季(IDEA工具)
1168077 学习 · 18753 问题
相似问题