import java.util.Arrays;;public class ScoreSort { int[] scores={89,-23,64,91,119,52,73}; public static void main(String[] args) { System.out.println("考試成績(jī)的前三名為:"); ScoreSort a = new ScoreSort(); a.showTop3(scores); } public void showTop3(int []scores){ Arrays.sort(scores); int num=0; for(int i=scores.length-1;i>=0;i++){ if(scores[i]<0||scores[i]>100){ continue; } num++; if(num<=3) System.out.println(scores[i]); else break; } } }為什么a.showTop3(scores); 括號(hào)內(nèi)score會(huì)報(bào)錯(cuò)Cannot make a static reference to the non-static field scores,要怎么改
1 回答
已采納

younghu
TA貢獻(xiàn)25條經(jīng)驗(yàn) 獲得超6個(gè)贊
這是基礎(chǔ)啊, ?你score 數(shù)組不是靜態(tài)的 ! 在scores前價(jià)格static好了
添加回答
舉報(bào)
0/150
提交
取消