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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

這樣子求成績(jī)的前三名好不好?

這樣子求成績(jī)的前三名好不好?

weibo_耗子12437133_0 2016-01-13 11:42:29
import java.util.Arrays;public class HelloWorld {? ??? ? //完成 main 方法? ? public static void main(String[] args) {? ? ? ? int[] scores={89 , -23 , 64 , 91 , 119 , 52 , 73};? ? ? ? HelloWorld hello=new HelloWorld();? ? ? ? hello.rank(scores);? ? }? ??? ? //定義方法完成成績(jī)排序并輸出前三名的功能 ? ?? ?public void rank(int[] scores){? ? ? ?int[] finalScor=new int [scores.length];? ? ? ?int i=0;? ? ? ?Arrays.sort(scores);? ? ? ?for(int score:scores){? ? ? ? ? ?if(score>=0&&score<=100){?? ? ? ? ? ? ? ?finalScor[i]=score;? ? ? ? ? ? ? ?i++;? ? ? ? ? ?}? ? ? ?}? ? ? ?for(int j=i-1;j>i-4;j--){? ? ? ? ? ?System.out.println(finalScor[j]);? ? ? ?}? ?}}
查看完整描述

3 回答

?
明云

TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超1個(gè)贊

你確定你寫的是成績(jī)? 上面的數(shù)組還有負(fù)數(shù)?后面取成績(jī)的范圍為什么是小于100?你數(shù)組里還有個(gè)119.。。。

查看完整回答
1 反對(duì) 回復(fù) 2016-01-13
?
心鈞

TA貢獻(xiàn)11條經(jīng)驗(yàn) 獲得超2個(gè)贊

int[] scores = { 89, -23, 64, 91, 119, 52, 73 };
?? ??? ?for (int i = 0; i < scores.length - 1; i++) {
?? ??? ??? ?for (int j = 0; j < scores.length - i - 1; j++) {
?? ??? ??? ??? ?if (scores[j] < scores[j + 1]) {
?? ??? ??? ??? ??? ?int temp = scores[j];
?? ??? ??? ??? ??? ?scores[j] = scores[j + 1];
?? ??? ??? ??? ??? ?scores[j + 1] = temp;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ??? ?int[] newscores;
?? ??? ?newscores = Arrays.copyOfRange(scores, 0, 3);
?? ??? ?for (int i : newscores) {
?? ??? ??? ?System.out.print(i+";");
?? ??? ?}
這樣也可以……

查看完整回答
反對(duì) 回復(fù) 2016-01-29
?
Its_forever

TA貢獻(xiàn)361條經(jīng)驗(yàn) 獲得超328個(gè)贊

可以啊,思想都是一樣的,先sort后反著打印。也可以自己寫一個(gè)排序的功能,從大到小。然后打印前三。


查看完整回答
反對(duì) 回復(fù) 2016-01-13
  • 3 回答
  • 0 關(guān)注
  • 1422 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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