package?helloworld;
import?java.util.Arrays;
/**
?*
?*?@author?Y
?*/
public?class?HelloWorld?
{
????public?static?void?main(String[]?args)?
????{
????????int[]scores={89?,?-23?,?64?,?91?,?119?,?52?,?73};
????????HelloWorld?hello=new?HelloWorld();
????????hello.put(scores);
????????
????????
?????}
????public??void?put(int[]score){
??????Arrays.sort(score);
??????for(int?i=score.length;i>score.length-3;i--)
??????System.out.print(score[i]);
????}
????
????
????錯誤:?。?????Exception?in?thread?"main"?java.lang.ArrayIndexOutOfBoundsException:?7
????at?helloworld.HelloWorld.put(HelloWorld.java:25)
????at?helloworld.HelloWorld.main(HelloWorld.java:18)
C:\Users\123\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53:?Java?returned:?1
構(gòu)建失敗?(總時間:?3?秒)
2016-03-23
int?i=score.length;i>score.length-3;i-- ?錯了,score.length應(yīng)該是7,當(dāng)i=7的時候,scores[7]就越界了,因為score下標(biāo)最大只到6,
2016-04-01
數(shù)組下標(biāo)越界
2016-03-28
scores.length是7 ,但是數(shù)組下標(biāo)最大是6 所以應(yīng)該scores.length-1 ,代碼里還有一些空格的問題
2016-03-26
越界了i=score.length 但是 0<=i<score.length
2016-03-23
角標(biāo)錯了 ? 一樓說的對
2016-03-23
scores[i]里的i值是從零開始,int?i=score.length改為int?i=score.length-1,希望可以幫到你