亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

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

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 回復 有任何疑惑可以回復我~

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

0 回復 有任何疑惑可以回復我~
#1

大尾鱸鰻 提問者

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

慕前端7469816 回復 大尾鱸鰻 提問者

他要求是列出在0-100的有效分數的前三名
2017-03-11 回復 有任何疑惑可以回復我~
#3

大尾鱸鰻 提問者 回復 慕前端7469816

??!謝謝沒認真看題
2017-03-12 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

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

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號