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

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

我這種寫法相比答案那個更好,可以解釋一下嗎

import java.util.Arrays;

public class HelloWorld {

? ??

? ? //完成 main 方法

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

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

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

? ? ? ? HelloWord hello = new HelloWord();

? ? ? ? hello.sort(scores);

? ? }

? ??

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

? ? public void sort(int[] arr){

? ? ? ? Arrays.sort(arr);

? ? ? ? int num = 0;

? ? ? ? int count = 0;

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

? ? ? ? ? ? if(count<3){

? ? ? ? ? ? ? ? num = arr[i];

? ? ? ? ? ? ? ? System.out.println(num);

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

? ? ? ? ? ? }

? ? ? ? }

? ? }


正在回答

2 回答

import java.util.Arrays;

public class HelloWorld {

public void sortArrays(int[] nums){

int count=0;

Arrays.sort(nums);

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

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

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

count++;

if(count==3) break;

}

}

public static void main(String[] args){

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

HelloWorld helloworld=new ?HelloWorld();

helloworld.sortArrays(nums);

}

}


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

這個方法并沒有判斷成績的有效性所以運行結(jié)果是119,91,81是不對的

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

大尾鱸鰻 提問者

有效性是什么意思,他的要求不是排列出前三名嗎
2017-03-10 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕前端7469816 回復(fù) 大尾鱸鰻 提問者

他要求是列出在0-100的有效分?jǐn)?shù)的前三名
2017-03-11 回復(fù) 有任何疑惑可以回復(fù)我~
#3

大尾鱸鰻 提問者 回復(fù) 慕前端7469816

啊!謝謝沒認(rèn)真看題
2017-03-12 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

我這種寫法相比答案那個更好,可以解釋一下嗎

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

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

幫助反饋 APP下載

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

公眾號

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