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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java中循環(huán)可以隨意嵌套么?

java中循環(huán)可以隨意嵌套么?

斷橋丶曉風(fēng)殘月 2016-06-29 17:04:50
import java.util.Arrays; public class Demo{ ?????? public static void main(String[] args){ ????????????? int[] scores={89,-23,64,91,119,52,73} ????????????? Demo hello=new Demo(); ????????????? System.out.println("考試成績的前三名為:"); ????????????? hello.getScores(scores); ?????? } ?????? public int[] getScores(scores){ ?????? Arrays.sort(scores); ?????? int count=0; ?????? if(count<3){ ???????? for(int i=scores.length-1;i--){ ????????????? if(scores[i]<0||scores[i]>100){ ???????????????? continue; ???????????? }else{ ???????????????????? System.out.println(scores[i]); ???????????????????? count++; ???????????? } ??????? } ????? } } 代碼要實現(xiàn)輸出考試成績的前三名。 }
查看完整描述

3 回答

已采納
?
綠洲仙人球

TA貢獻(xiàn)39條經(jīng)驗 獲得超47個贊

循環(huán)怎么嵌套應(yīng)該和需求有關(guān)系,我讀了一下題主的代碼,就貼出來的這部分而言是無法運(yùn)行的,一是代碼語法有點(diǎn)錯誤,而是根據(jù)需求,要輸出考試成績的前三名,代碼的邏輯也有點(diǎn)問題,在沒有大改動題主的代碼的基礎(chǔ)上,實現(xiàn)了功能,代碼如下

public?class?Demo?{
	public?static?void?main(String[]?args)?{
		int[]?scores?=?{89,?-23,?64,?91,?119,?52,?73?};
		Demo?hello?=?new?Demo();
		System.out.println("考試成績的前三名為:");
		hello.getScores(scores);
	}

	public?void?getScores(int[]?scores)?{
		Arrays.sort(scores);
		int?count?=?0;
		for?(int?i?=?scores.length?-?1;;?i--)?{
			if?(count?<?3)?{
				if?(scores[i]?<?0?||?scores[i]?>?100)?{
					continue;
				}?else?{
					System.out.println(scores[i]);
					count++;
				}
			}
		}
	}
}

需要把for循環(huán)和if?(count?<?3) 的判斷調(diào)換一下位置,這樣就沒有問題了

查看完整回答
3 反對 回復(fù) 2016-06-30
點(diǎn)擊展開后面3
?
斷橋丶曉風(fēng)殘月

TA貢獻(xiàn)32條經(jīng)驗 獲得超15個贊

有人可以解答一下么?

查看完整回答
反對 回復(fù) 2016-06-29
?
qq_匡璐_0

TA貢獻(xiàn)96條經(jīng)驗 獲得超96個贊

public void main(String[] args) {
? ?int[] scores = {89, -23, 64, 91, 119, 52, 73};
? ?Arrays.sort(scores);
? ?System.out.println("考試成績的前三名為:");
? ?for(int i = 0 ;i<3;i++){
? ? ? ?int j = scores[scores.length-1-i];
? ? ? ?System.out.println(j);
? ?}
}

查看完整回答
反對 回復(fù) 2016-06-30
  • 3 回答
  • 1 關(guān)注
  • 2433 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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