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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

大家進(jìn)來幫我看看哪里出現(xiàn)了錯(cuò)誤了,我輸出的結(jié)果是全部輸出了,不管怎么判斷都是這樣的,哪里的邏輯出現(xiàn)了錯(cuò)誤了

/*
?要求:
1、?考試成績(jī)已保存在數(shù)組?scores?中,數(shù)組元素依次為?89?,?-23?,?64?,?91?,?119?,?52?,?73
2、?要求通過自定義方法來實(shí)現(xiàn)成績(jī)排名并輸出操作,將成績(jī)數(shù)組作為參數(shù)傳入
3、?要求判斷成績(jī)的有效性(?0—100?),如果成績(jī)無效,則忽略此成績(jī)
*/
class?Demo4?{
	public?static?void?main(String[]?args)?{
		int[]?scores?=?{?89,?-23,?64,?91,?119,?52,?73?};
		print(scores);
	}

	public?static?void?print(int[]?arr)?{
		for?(int?i?=?0;?i?<?arr.length;?i++)?{		//將數(shù)組的元素你從大到小排序
			for?(int?j?=?i?+?1;?j?<?arr.length;?j++)?{
				if?(arr[i]?<?arr[j])?{
					int?temp?=?arr[i];
					arr[i]?=?arr[j];
					arr[j]?=?temp;
				}
			}
		}
		
		for?(int?i?=?0;?i?<?arr.length;?i++)?{
			int?count=1;
			if(?arr[i]<0?||?arr[i]?>?100?){
				continue;
			}
			count++;
			if?(count>3)?{
				break;
			}
			
			System.out.println(arr[i]);	
			/*if?(0?<?arr[i]?&&?arr[i]?<=?100?)?{								
				System.out.println(arr[i]);				
				
				if?(count>3)?{
					break;
				}
				count++;
			}*/
		}
	}

}

我找到錯(cuò)誤了,是我的計(jì)數(shù)器定義的位置錯(cuò)了,應(yīng)該定義在for循環(huán)外邊,我定義在for里邊相當(dāng)于我的計(jì)數(shù)器在每次循環(huán)的時(shí)候都是從零開始的

正在回答

3 回答

import java.util.Arrays;

public class HelloWorld {


? ? public static void main(String[] args) {

int[] scores={89,-23,64,91,119,52,73};

HelloWorld hello= new HelloWorld();

System.out.println("成績(jī)前三名的是:");

hello.getScores(scores);

}

public void getScores(int[] scores)

{

Arrays.sort(scores);

int sum=0;

for (int i=scores.length-1;i>=0;i--)

{

if(scores[i]<0||scores[i]>100)

{

continue;

}

sum++;

if(sum>3)

{

break;

}

System.out.println(scores[i]);

}

}


}


? ??

? ??


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

import java.util.Arrays;

public class All {

/*

*1、 考試成績(jī)已保存在數(shù)組 scores 中,數(shù)組元素依次為 89 , -23 , 64 , 91 , 119 , 52 , 73


*2、 要求通過自定義方法來實(shí)現(xiàn)成績(jī)排名并輸出操作,將成績(jī)數(shù)組作為參數(shù)傳入


*3、 要求判斷成績(jī)的有效性( 0—100 ),如果成績(jī)無效,則忽略此成績(jī)

*/ ? ?

? ? //完成 main 方法

? ? public static void main(String[] args) {

? ? int[] scores={89,-23,64,91,119,52,73};?

? ? All outscores=new All();

? ? outscores.three(scores);

? ? } ??

? ? //定義方法完成成績(jī)排序并輸出前三名的功能

public void three(int[] scores){

Arrays.sort(scores);

int count=1;

for(int i=scores.length-1;i>=0;i--){

if(scores[i]<0 || scores[i]>100){

continue;

}

if(count<=3) {

System.out.println(scores[i]);

count++;

}

}

}

}

? ?

? ??

? ??

? ??


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

沒有說明你的問題

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

imooc_粉絲 提問者

不好意思,我給忘記了,按照題目的要求只需要輸出前三名即可,我的結(jié)果卻是把結(jié)果全部都輸出來了,我找不出錯(cuò)誤在哪
2016-11-04 回復(fù) 有任何疑惑可以回復(fù)我~
#2

imooc_粉絲 提問者

我找到問題了,我的計(jì)數(shù)器定義在for循環(huán)內(nèi)了,相當(dāng)于每次循環(huán)我的計(jì)數(shù)器都是從零開始計(jì)算的
2016-11-04 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

大家進(jìn)來幫我看看哪里出現(xiàn)了錯(cuò)誤了,我輸出的結(jié)果是全部輸出了,不管怎么判斷都是這樣的,哪里的邏輯出現(xiàn)了錯(cuò)誤了

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

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

幫助反饋 APP下載

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

公眾號(hào)

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