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

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

寫了個返回數(shù)組的方法實現(xiàn)了,調(diào)試沒問題,大佬們請幫看看有沒有需要改進(jìn)的地方

import java.util.Arrays;

public class HelloWorld {

public int[] showTop3(int[] score) {

Arrays.sort(score);

? ? ? ? int i=0,j;

? ? ? ? int[] Top3=new int[3];

? ? ? ? ? ? for(j=score.length-1; j>0; j--) {

? ? ? ? ? ? if (score[j]>=0 && score[j]<=100){

? ? ? ? ? ? ? ? ? ? Top3[i] = score[j];

? ? ? ? ? ? ? ? ? ? i++;

? ? ? ? ? ? ? ? ? ? if(i>=3)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ??

? ? ?}

? ? ? ? return Top3;

? ?}

public static void main(String[] args) {

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

HelloWorld test = new HelloWorld();

int[] top3 = test.showTop3(scores);

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

for(int score : top3) {

System.out.println(score);

}



}


}


正在回答

5 回答

感覺看上去有點違背習(xí)慣,建議將public static void main(String[] args) 這段放前邊,后邊的類在后邊看上去舒服些

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

沒做數(shù)據(jù)合法檢測,附上

import java.util.Arrays;

public class HelloWorld {
?? ?
??? //完成 main 方法
??? public static void main(String[] args) {
?????? ?
??????? int [] scores = {89,-23,64,91,119,52,73};
??????? HelloWorld test = new HelloWorld();
??????? test.Output(scores);
?????? ?
?????? ?
??? }
?? ?
??? //定義方法完成成績排序并輸出前三名的功能
??? public void Output(int [] array){
??????? Arrays.sort(array);
??????? int i = 0,j = array.length-1,num = 0;
??????? while (array[i] < 0)
??????? {
??????????? i++;
??????? }
??????? while (array[j] > 100)
??????? {
??????????? j--;
??????? }
??????? System.out.println("考試成績的前三名為:" + "\n");
??????? while (j >= i && num < 3)
??????? {
??????????? System.out.println(array[j] + "\n");
??????????? j--;
??????????? num++;
??????? }
??? }
???

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

確定調(diào)試會沒有問題嗎?你定義的數(shù)組名是? scores,用的時候卻變成了score.....

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

qq_慕仔212396

在方法中用的是形參名
2019-03-03 回復(fù) 有任何疑惑可以回復(fù)我~
#2

Viva啦啦啦Vida 回復(fù) qq_慕仔212396

對耶,這樣也可以~
2019-03-04 回復(fù) 有任何疑惑可以回復(fù)我~

import java.util.Arrays;

public class HelloWorld {

? ? //完成 main 方法

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

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

? ? }

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

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

? ? ? ? Arrays.sort(scores);

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

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

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

? ? ? ? }

? ? }

}

/*你覺得這段代碼如何?*/

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

沒毛病? 挺好的

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

舉報

0/150
提交
取消

寫了個返回數(shù)組的方法實現(xiàn)了,調(diào)試沒問題,大佬們請幫看看有沒有需要改進(jìn)的地方

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

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

幫助反饋 APP下載

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

公眾號

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