import?java.util.Arrays;
public?class?HelloWorld?{
????
????//完成?main?方法
????public?static?void?main(String[]?args)?{
????????
????????HelloWorld?shuchu=new?HelloWorld();
????????int?scores[]={89,-23,64,91,119,52,73};
????????shuchu.chengji(scores);
????}
????
????//定義方法完成成績排序并輸出前三名的功能
????public?void?chengji(int?scores[])
????{???
????????int?count=0;
????????Arrays.sort(scores);
????????for(int?j=scores.length-1;j>=0&&count>=3;j--)
????????{
????????????if(scores[j]<0||scores[j]>100)
??????????????continue;????
????????????System.out.println(scores[j]);
????????????count++;
????????}
????}
???
}
2015-06-12
for()循環(huán)語句里面的判斷條件有錯(cuò)。count是小于3,而不是count >= 3; 因?yàn)閒or語句一開始執(zhí)行就結(jié)束了,count = 0,不滿足條件。為什么不能等于3呢,因?yàn)閏ount 是從零開始的,只需要輸出三個(gè)數(shù)就好,count最大為2.
2015-06-09
用Eclipse軟件,可以出現(xiàn)結(jié)果,結(jié)果也是對(duì)的,但是在這里就不能顯示結(jié)果,求指明 package?com.immoc; public?class?HelloWorld?{ ???? ????//完成?main?方法 ????public?static?void?main(String[]?args)?{ ????????int[]?scores={89,-23,64,91,119,52,73}; ????????HelloWorld?hello=new?HelloWorld(); ????????hello.get(scores); ???????? ???????? ???????? ????} ???? ????//定義方法完成成績排序并輸出前三名的功能 ???? ????public?void?get(int[]?score){ ????????System.out.println("考試成績的前三名為:?"); ????????????for(int?i=0;i<score.length-1;i++){ ?????????????for(int?j=i+1;j<score.length;j++){ ????????????????????if(score[i]<score[j]){ ????????????????????????int?t; ????????????????????????t=score[i]; ????????????????????????score[i]=score[j]; ????????????????????????score[j]=t; ?????????????????????????} ????????????????} ????????????} ????????????int?j=0; ????????????for(int?i=0;i<score.length;i++){ ????????????????if((0<score[i])&&(score[i]<100)){ ????????????????????score[j]=score[i]; ????????????????????j++; ????????????????} ????????????} ????????????for(int?i=0;i<3;i++){ ????????????????System.out.println(score[i]); ???????????????} ????????????} ?????????? ?????????? ???????? ????}