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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

求大神解答;運(yùn)行結(jié)果為:考試成績(jī)的前三名為[I@15db9742,運(yùn)行結(jié)果應(yīng)該是前三名的成績(jī),怎么是亂碼,哪里錯(cuò)了

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(); ? ?

? ? int [] count= hello.show(scores);

? ? System.out.println("考試成績(jī)的前三名為"+count);

? ? }

? ??

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

? ? public int [] show(int [] scores){

? ? ? ? Arrays.sort(scores);

? ? ? ? int num = 0;

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

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

? ? ? ? ? ? ?continue;

? ? ? ? ?}

? ? ? ? ?num++;

? ? ? ? ?if(num > 3){

? ? ? ? ? ? ?break;

? ? ? ? ?}

? ? ? ? }

? ? ? ? return scores;

? ? }

? ??

? ??

? ??

? ??

? ??

? ??

? ??

? ??

? ??

}


正在回答

5 回答

1.System.out.println("考試成績(jī)的前三名為"+count);

這里count是一個(gè)數(shù)組,不能直接輸出,需要用Arrays.toString()類輸出


2.return scores;

你返回的scores,其實(shí)在方法show里,你并沒有改變scores數(shù)組里的任何值,返回的還是原來的scores,里面的元素并沒有改變。


3.你寫的代碼還有太多需要改進(jìn)的地方,太過冗余,多參考慕課給的正確答案。

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

慕少224234 提問者

非常感謝!
2018-05-21 回復(fù) 有任何疑惑可以回復(fù)我~

輸出的是數(shù)組的指針,感覺題主的需求是輸出整個(gè)數(shù)組吧。可以用Arrays.deepToString,Arrays.deepToString與Arrays.toString不同之處在于,Arrays.deepToString更適合打印多維數(shù)組

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

額,那個(gè)不是亂碼,是內(nèi)存的地址值,你要用數(shù)組輸出前三名的話,應(yīng)該加個(gè)for循環(huán)給count增加標(biāo)簽,不過我還是不知道你的需求是什么

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

import java.util.Arrays;

pubilc class HelloWorld{

public static void main(String[] args){

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

HelloWorld hello=new HelloWorld();

hello.getScore(scores);

}

public void getScore(int[] scores){

Arrays.sort(scores);

int count=0;

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

if(scores[i]<100&&scores[i]>0)

{

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

count++;

}

if(count>=3)

break;

}

}

}



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

慕少224234 提問者

是的,這個(gè)是定義的無返回值的方法,這個(gè)我試過成功了,但是我想試下有返回值的方法。還有就是我想知道什么情況下,使用帶返回值的,什么情況下,使用無返回值的方法。
2018-05-21 回復(fù) 有任何疑惑可以回復(fù)我~

定義方法那里?

public int 【】 ?把【】去掉;

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

舉報(bào)

0/150
提交
取消

求大神解答;運(yùn)行結(jié)果為:考試成績(jī)的前三名為[I@15db9742,運(yùn)行結(jié)果應(yīng)該是前三名的成績(jī),怎么是亂碼,哪里錯(cuò)了

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

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

幫助反饋 APP下載

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

公眾號(hào)

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