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

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

正在回答

4 回答

先把數(shù)組按從小到大排序好,然后從后往前取三個(有效?。。。┑某煽?/p>

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

把有效數(shù)據(jù)排序,從最大的數(shù)往下取三位就好。

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

注意任務(wù)一的第四、五條,增加判斷成績是否有效的條件,定義一個變量用來記錄當(dāng)前有效成績的個數(shù)。

import java.util.Arrays;

public class HelloWorld {

? ? ?//完成 main 方法

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

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

? ? ? ? HelloWorld hello=new HelloWorld();

? ? ? ? System.out.println("考試成績的前三名為:");

? ? ? ? hello.resultsSort(scores);

? ? ? ??

? ? }

? ??

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

? ? public void resultsSort(int[] scores){

? ? ? ? int count=0;

? ? ? ? Arrays.sort(scores);

? ? ? ? for(int i=scores.length-1;(i>=0&&count<3);i--){

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

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

? ? ? ? ? ? ? ? count++;

? ? ? ? ? ? }else

? ? ? ? ? ? continue;

? ? ? ? }

? ? }

? ??

? ??

? ??

? ??

? ??

? ??

? ??

? ??

? ??

}


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

對成績從小到大排序,然后倒序輸出,規(guī)定一個變量判斷是否有效成績,如果這個成績有效,則變量加一,直到變量等于3退出循環(huán)。

public static void main(String[] args) {
??int []scores={89,-23,64,91,119,52,73};
??Arrays.sort(scores);
??int count=1; //標(biāo)記有效成績
??System.out.println("成績前三名:");
??output(scores,count);
?}
?public static void output(int []s,int c) {
??for(int i=s.length-1;i>=0;i--) {
???if (s[i]>=0&&s[i]<=100&&c<=3) {
????c++;
????System.out.print(s[i]+" ");
???}
????
??}
?}

可參考我的代碼


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

舉報

0/150
提交
取消

怎么才能保證它輸出的有效成績是前3名呢

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

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

幫助反饋 APP下載

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

公眾號

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