import?java.util.*;
public?class?HelloWorld?{
????
????//完成?main?方法
????public?static?void?main(String[]?args)?{
????????
????????int[]?scores={89,-23,64,91,119,52,73};
????????HelloWorld?sorts=new?HelloWorld();
????????getArrays(scores);
????????
????????
????}
????
????//定義方法完成成績排序并輸出前三名的功能
????
????public?static?void?getArrays(int[]?scores){
????????Arrays.sort(scores);
????????int[]?score2=scores;
????????int[]?score3={0,0,0};
????????int?cout=0;
????????for(int?i=score2.length;i>=0;i--){
????????????if(score2[i]>100&&score2[i]<0)
????????????continue;
????????????cout+=1;
????????????score3[cout-1]=score2[i];
?????????????if(cout>3)
?????????????break;
????????????
????????}
????????System.out.println("考試成績的前三名為:\n"+
????????score3[0]+score3[1]+score3[2]);
????}
2016-04-30
這是拋出ArrayIndexOutOfBoundsException異常,也就是說你的數(shù)組超出了范圍,? for(int i=score2.length-1;i>=0;i--)這里面的score2.length要減1,?if(cout>=3)這里面的cout是大于等于3。
2022-03-29
內(nèi)容看懂了就好
fpupmikwxdtkjhaajrrkgilxmtuzzpcrlcbxctjnhosoosruutedvmqojbxuylfmrwpbjblacxarmkcdumdnwyncnhzmsmcewdvhkgyqzpubhcmqnpjalqfttqsvassqldjuguewlif
2016-04-30
第1行導(dǎo)入Arrays方法
第21行:score2[i]>100&&score<0;這個數(shù)不存在,應(yīng)該為或||
2016-04-30
21行 :這個大于100 ?并且要小于0 這種數(shù)字不存在吧!你改一下試試(||)