最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

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

請(qǐng)幫忙找一下這里邊的語(yǔ)法錯(cuò)誤。希望大佬提些修改建議,謝謝

public class HelloWorld {

? ??

? ? //完成 main 方法

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

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

? ? ? ? HelloWorld hello=new HelloWorld();

? ? ? ? hello.Seiseki(scores);

? ? }

? ??

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

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

? ? ? ? int[] scores=new int[7];

? ? ? ? int max=scores[0];

? ? ? ? int second=scores[1];

? ? ? ? int third=scores[2];

? ? ? ? for(int i=0;i<scores.length;i++){

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

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? ? ? if(scores[i]>max){

? ? ? ? ? ? ? ? max=scores[i];

? ? ? ? ? ? }else if(scores[i]>second){

? ? ? ? ? ? ? ? second=scores[i];

? ? ? ? ? ? }else if(scores[i]>third){

? ? ? ? ? ? ? ? third=scores[i];

? ? ? ? ? ? }

? ? ? ? }

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

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

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

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

? ? }

}


正在回答

4 回答

有點(diǎn)問(wèn)題,你看如果數(shù)組里的第三個(gè)數(shù)比第一個(gè)大,就會(huì)把第三個(gè)值賦給第一個(gè)而且比較過(guò)的數(shù)之后就用不到了,這時(shí)候你的第一個(gè)數(shù)值就被覆蓋了,默認(rèn)是第一個(gè)數(shù)值比第二個(gè)大,也比第三個(gè)大,但是實(shí)際情況并不是這樣的,修改的話建議你可以用兩層循環(huán)的冒泡排序,當(dāng)然也可以用java特有的排序函數(shù),嗯嗯,就這樣。

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

其實(shí)編程要求提示那里已經(jīng)說(shuō)了,可以利用Arrays.sort(scores);進(jìn)行排序,再倒序循環(huán),就方便很多

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

import java.util.*;

public class HelloWorld {


? ? //完成 main 方法

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

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

HelloWorld hello=new HelloWorld();

hello.print(scores);? ??

? ? }

? ??

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

? ? public static void print(int[] scores) {

Arrays.sort(scores);

int count=0;

for(int i=scores.length-1;i>=0||count<=3;i--) {

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

count++;

if(count<3) {

System.out.print(scores[i]+" ");

? ? }

else if(count==3)

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

? ? }

? ? }

? ? }

? ??

}

這是我的代碼你可以看看

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

ARUKANA 提問(wèn)者

謝謝,我明白了
2019-03-10 回復(fù) 有任何疑惑可以回復(fù)我~

scores你是自己傳進(jìn)去的為什么要重新開(kāi)空間?這里已經(jīng)錯(cuò)了

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

舉報(bào)

0/150
提交
取消

請(qǐng)幫忙找一下這里邊的語(yǔ)法錯(cuò)誤。希望大佬提些修改建議,謝謝

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

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

幫助反饋 APP下載

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

公眾號(hào)

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