关于数组越界的问题
package com.test3;
/*
*
* 功能:输出保存在数组中的前三名
*/
import java.util.Arrays;
public class test8 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int []scores = { 89 , -23 , 64 , 91 , 119 , 52 , 73};
test8 sys = new test8();
sys.getScore(scores);
}
public int[] getScore(int score[]){
Arrays.sort(score);
int count = 0;
for(int i=score.length;i>=0;i--){
if((score[i]>100)||(score[i]<0)){
continue;
}
count++;
if(count>3){
break;
}
System.out.println("考试成绩的前三名为:");
System.out.println(score[i]);
}
return score;
}
}我想要输出保存在数组中的前三名的成绩,可是eclipse提示数组越界呢,这是为什么呢?
这是运行结果:
