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

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

不理解,求各位大神道友解答,謝謝謝謝謝.........

package jin;

import java.util.Arrays;

?


public class HelloWorld1{

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

? ? ?HelloWorld1 hello = new HelloWorld1();

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

? ? ? ? ? Arrays.sort(scores);

? ? ? ? ? int[] newArrays = hello.getnewArrays(scores);

? ? ? ? ? ? ?System.out.println(Arrays.toString(newArrays));

}

? ? ? ? ??

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

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

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

?continue;

? ? ?}

? ? ?int[] newArrays= {scores[i]};

?// ? System.out.println(Arrays.toString(newArrays));

? ?

?}

? ? ? return newArrays; //(這里為什么不能返回數(shù)組?????)

? ? ? ? ? ? ? ? ? ? ? ? //(而在方法中設(shè)定無返回值,直接輸出newArrays就可以! 求解,謝謝謝?。。?!)

?

?}

?

??


}


正在回答

3 回答

??? public static void main(String[] args) {
??????? HelloWorld hello = new HelloWorld();
?????? ?
??????? int[] scores =new int[]{89,-23,64,91,119,52,73};
?????? ?
??????? System.out.println("考試成績的前三名為:");
??????? hello.print(scores);?????? ?
??? }
?? ?
??? //定義方法完成成績排序并輸出前三名的功能
??? public void print(int[] scores){
??????? //統(tǒng)計有效成績個數(shù)
??????? int count = 0;
?????? ?
??????? //先對數(shù)組進行排序(升序)
??????? Arrays.sort(scores);
?????? ?
??????? //輸出前三名(由于是升序,所以需要倒序遍歷)
??????? for(int i=scores.length-1;i>=0;i--){
??????????? if(scores[i]<0 || scores[i]>100){
??????????????? //如果成績不在0-100范圍之內(nèi),忽略結(jié)此次成績,束本次循環(huán),接下一次循環(huán),否則繼續(xù)
??????????????? continue;
??????????? }???
??????? //有效,個數(shù)加1
??????? count++;
?????? ?
??????? //輸出成績
??????? System.out.println(scores[i]);
?????? ?
??????? //如果成績個數(shù)大于三了,結(jié)束循環(huán)
??????? if(count>=3){
??????????? break;
??????? }
?????????? ?
??????? }
??? }

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

三分世界 提問者

謝謝回復??!不過我只是想問為什么這里不能返回數(shù)組,不是要實現(xiàn) (輸出有效成績前三名)的功能
2016-01-27 回復 有任何疑惑可以回復我~

import java.util.Arrarys;

public class HelloWorld {

? ??

? ? //完成 main 方法

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

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

? ? ? ? HelloWorld score = new HelloWorld();

? ? ? ? ? score.fa(scores);

? ? ? ??

? ? ? ??

? ? }

? ??

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

? ??

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

? ? ? ? int k;

? ? ? ? Arrares.sort(scores);

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

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

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

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

? ? ? ? ? ? ? ?k++;

? ? ? ? ? ? ? ?if(k==2){

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

? ? ? ? ? ? ? ?}

? ? ? ? ? ? }

? ? ? ? ? ??

? ? ? ? }

? ? ? ??

? ? }

? ??

? ??

? ? 看看我寫的超簡單


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

因為你的數(shù)組創(chuàng)建在循環(huán)里了= =也就是你每循環(huán)一次,都創(chuàng)建一次= =你把他放到for前面創(chuàng)建就行了。不過你整個代碼倒錯都是錯,拿出去結(jié)果也是錯的

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

舉報

0/150
提交
取消
Java入門第一季(IDEA工具)升級版
  • 參與學習       1167313    人
  • 解答問題       18530    個

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

進入課程

不理解,求各位大神道友解答,謝謝謝謝謝.........

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

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

幫助反饋 APP下載

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

公眾號

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