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

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

幫忙看看為什么錯(cuò)吧,腦子無(wú)法思考了

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

? ? ? ??

? ? ? ? ? ? hello.topThree(scores);

? ? ? ??

? ? }

? ??

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

? ??

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

? ? ? ? Arrays.sort(scores);

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

? ? ? ? if(scores[i]>=0 && scores[i]<=100){System.out.println("考試成績(jī)的前三名為:");

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

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

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

? ? ? ? }

? ? ? ? }

? ? ? ??

? ? ? ? }


正在回答

8 回答

  1. 將負(fù)數(shù)和過(guò)一百的拋出 ? 就是-23和119

    用if語(yǔ)句 ?拋出是continue ?

    拋出后所有的都留下 ? 你使用的是大于0&&小于100

    這樣對(duì)后面的施行方法無(wú)法進(jìn)行具體編程

    合適的進(jìn)行輸出 ?不合適的沒(méi)寫(xiě)怎么進(jìn)行處理

    而如果用拋出 ? 不合適的拋出了 ? 合適的下面接著處理

    拋出語(yǔ)句是

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

    continue ? ?

    }

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

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

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

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

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

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

    你這樣不對(duì) ? ? 你應(yīng)該

    private void score(int[] scores) { ? ? ? ? ? //定義方法

    ? ? ? ?Arrays.sort(scores); ? ? ? ? ? ? ? ? ? ? ? ?//遍歷數(shù)組 ? ? ? ? ? 這倆你也寫(xiě)了

    ? ? ? ?int num=0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//定義名次 ? ?初始化為0

    ? ? ? ?for(int i=scores.length-1;i>0;i--){ ? ? ? ? ? ? ? //定義i ? 對(duì)數(shù)組倒敘開(kāi)始

    ? ? ? ? ? ? ? if (scores[i]<0 || scores[i]>100){ ? ? ? ? ?//前面說(shuō)的拋出不正常數(shù)字

    ? ? ? ? ? ? ? ? ? ? continue;

    ? ? ? ? ? ? ? ? ? ? }

    ? ? ? ? ? ? ? num++; ? ? ? ? ? ? ? ? ? ? ? ? //i 減個(gè)1 ? num減個(gè)1 ? 當(dāng)i 進(jìn)行三個(gè)時(shí) ? num為3 ? 前三名就確定了

    ? ? ? ? ? ? ? if (num>3) { ? ? ? ? ? ? ? ? ? //當(dāng)num大于3后 ?不在進(jìn)行 ? 斷開(kāi)方法為break

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

    ? ? ? ? ? ? ? ? ? ? }

    ? ? ? ? ? ? ? System.out.println(scores[i]); ? ? ? ? ? ? ? //i ?進(jìn)行了3位 ? ?輸出數(shù)組

    ? ? ? ? ? ? ? }? ?

? ? ? ? ? ? ? ? ? 思路:題意輸出前三名,當(dāng)出現(xiàn)數(shù)字時(shí)絕對(duì)會(huì)有相對(duì)應(yīng)的常量 ? ?咱們?cè)O(shè)置的是num

? ? ? ? ? ? ? ? ? ? ? ? ? ?在對(duì)正確數(shù)字進(jìn)行選擇時(shí)要先將異常數(shù)字拋出 ?就是前面說(shuō)的continue

? ? ? ? ? ? ? ? ? ? ? ? ? ?遍歷數(shù)組你知道了,也知道從后向前取值,所以取值就從數(shù)組最后一位length-1開(kāi)始一直到0

? ? ? ? ? ? ? ? ? ? ? ? ? 不能自己中斷要一直到0,要靠條件自動(dòng)停止,條件就是num>3, ?當(dāng)大于3時(shí)取值結(jié)束

? ? ? ? ? ? ? ? ? ? ? ? ? 方法返回值為scores[i],再在前面調(diào)用,這個(gè)你沒(méi)寫(xiě)錯(cuò) ?就不說(shuō)了



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

zsqangle 提問(wèn)者

非常感謝?。。。?/div>
2016-03-14 回復(fù) 有任何疑惑可以回復(fù)我~

最后改成了這樣,OK了。謝謝nosilence和各位的回答!

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("考試成績(jī)的前三名為:");

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

? ? ? ? ? ? hello.topThree(scores); ??

? ? }

? ??

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

? ??

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

? ? ? ? Arrays.sort(scores);

? ? ? ? int jj=0;

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

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

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

? ? ? ? int countt=++jj;

? ? ? ? ? ? if(countt>2){

? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ?}

? }

? ? ? ?}

}


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

你這樣寫(xiě)肯定不行的。

sort排序后是升序,即從大到小,為了輸出成績(jī)最高的前三個(gè),理論上是要輸出后面的三個(gè),又因?yàn)閿?shù)據(jù)里面有無(wú)效的數(shù)據(jù)(比如小于0;大于100),因此倒敘取后面的數(shù)據(jù)的時(shí)候,要檢驗(yàn)成績(jī)是否0>=0 && <=100,符合條件的輸出,并用一個(gè)int計(jì)數(shù)器來(lái)存儲(chǔ)已經(jīng)輸出了的有效成績(jī)個(gè)數(shù),每次輸出就++,滿3個(gè)了就break出循環(huán),結(jié)束。

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

zsqangle 提問(wèn)者

謝謝?。。。?!
2016-03-14 回復(fù) 有任何疑惑可以回復(fù)我~

從length-1到0 ? ?為for(int i=length-1;i>0:i--)

i要大于0 ? 不能大于等于 ? 這樣當(dāng)i為0時(shí)還會(huì)減1 ??

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

有相應(yīng)的變量 ? ?num是變量

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

額,還要改

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

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

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


0 回復(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};

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

? ? ? ??

? ? ? ? ? ? hello.topThree(scores);

? ? ? ??

? ? }

? ??

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

? ??

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

? ? ? ? Arrays.sort(scores);

/*只是將你的for終止條件改變,你的循環(huán)只需要運(yùn)行兩次就得出結(jié)果了,但不具有普適性,如果前兩個(gè)都大于100就不行了。

http://idcbgp.cn/qadetail/124709 ?看下我的,還有標(biāo)準(zhǔn)答案 */

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

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

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

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

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

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

? ? ? ? ? ? }

? ? ? ? }

? ? ? ??

? ? }

?}



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

既然是for循環(huán)。何必要scores[i-1],scores[i-2],scores[3]呢,直接scores[i]就可以了。

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

舉報(bào)

0/150
提交
取消
Java入門(mén)第一季(IDEA工具)升級(jí)版
  • 參與學(xué)習(xí)       1167326    人
  • 解答問(wèn)題       18530    個(gè)

0基礎(chǔ)萌新入門(mén)第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語(yǔ)法開(kāi)始

進(jìn)入課程

幫忙看看為什么錯(cuò)吧,腦子無(wú)法思考了

我要回答 關(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)