亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

求指導,不能輸出答案

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++;
????????}
????}
???
}


正在回答

2 回答

for()循環語句里面的判斷條件有錯。count是小于3,而不是count >= 3; 因為for語句一開始執行就結束了,count = 0,不滿足條件。為什么不能等于3呢,因為count 是從零開始的,只需要輸出三個數就好,count最大為2.

1 回復 有任何疑惑可以回復我~
用Eclipse軟件,可以出現結果,結果也是對的,但是在這里就不能顯示結果,求指明
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]);
???????????????}
????????????}
??????????
??????????
????????
????}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

求指導,不能輸出答案

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號