用eclipse驗(yàn)證出現(xiàn)這樣。。。。請(qǐng)問哪錯(cuò)了,請(qǐng)大神指教
考試成績的前三名為:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at com.lianxi.Demo01.yang(Demo01.java:14)
at com.lianxi.Demo01.main(Demo01.java:8)
下面是我的代碼
package com.lianxi;
import java.util.Arrays;
public class Demo01 {
? ? public static void main(String[] args){
? ? Demo01 demo = new Demo01();
? ? int[] scores = {89,-23,64,91,119,52,73};
? ? System.out.println("考試成績的前三名為:");
? ? demo.yang(scores);
? ? }
? ? public void yang(int[] scores){
? ? Arrays.sort(scores);
? ? int j=0;
? ? for(int i=scores.length-1;i>=0;i++){
? ? if(scores[i] < 0||scores[i]>100){
? ? continue;
? ? }
? ? ? ?j++;
? ? ? ?if(j>=3)
? ? ? ? break;
? ? ? ?System.out.println(scores[i]);
? ? }
? ?
? ? }
}
2017-02-05
下標(biāo)越界,把for循環(huán)改成如下: