第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

自定義用戶輸入

package?com.imooc;
import?java.util.Arrays;
import?java.util.Scanner;

public?class?HelloWorld?{
	public?static?void?main(String[]?args){
		int[]?score?=?new?int[6];
		HelloWorld?hello?=?new?HelloWorld();
		Scanner?input?=?new?Scanner(System.in);
		
		for(int?i=0;i<6;i++){
			System.out.print("請輸入第"+(i+1)+"個人的成績:");
			score[i]?=?input.nextInt();
		}
		
		String?result?=?hello.getTop3(score);
		System.out.println("前三名的成績?yōu)椋?+result);
	}
	
	/**
	?*?求所有考試成績中的前三名
	?*?@return?前三名的成績
	?*/
	public?String?getTop3(int[]?score){
		int[]?top3?=?new?int[3];
		int?j?=?0;
		Arrays.sort(score);
		for(int?i=score.length-1;i>score.length-4;i--){
			if(score[i]?>100?||?score[i]?<?0)?continue;
			top3[j++]?=?score[i];
		}
		
		return?Arrays.toString(top3);
	}
}


正在回答

1 回答

for(int?i=score.length-1;i>score.length-4;i--){

????????????if(score[i]?>100?||?score[i]?<?0)?continue;

????????????top3[j++]?=?score[i];

????????}

你問題出在 ??i>score.length-4 ? 這里,

你運行你的代碼可以發(fā)現(xiàn)你如果輸入的數(shù)字全部符合1~100的范圍的話,程序可以正確運行。

問題就是,你sort(score)之后,你for遍歷的只有倒數(shù)的那三個分?jǐn)?shù),而如果其中一個分?jǐn)?shù)超過了100分的話,超過100的那個分?jǐn)?shù)被continue掉了,然后你遍歷的數(shù)就只剩兩個數(shù)了,所以結(jié)果就會顯示類似'''前三名的成績?yōu)椋篬100, 90, 0]'''之類的情況了。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

自定義用戶輸入

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號