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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java第一季最后一章節(jié) ,方法中的返回值類型為什么不可以用int[]

java第一季最后一章節(jié) ,方法中的返回值類型為什么不可以用int[]

謝兵 2016-03-06 16:45:36
package xunhuan;import java.util.Arrays;public class qiansanm {??? //完成 main 方法??? public static void main(String[] args) {?????? qiansanm hello=new qiansanm();??????? //定義有效前三名的變量?????? System.out.println("請輸入前三名的學員成績");??????? int[] scores={89,-23,64,91,119,52,73};??????? Arrays.sort(scores);??????? hello.nums(scores); ???? }??? //定義方法完成成績排序并輸出前三名的功能??? public int[] nums(int[] scores){?? ??? ? int one = 0;???????? for(int i=0; i<scores.length;i++){?????? ??? ???? ???????????? if(scores[i]<0||scores[i]>100){??????????????? continue;?? ???????????? }??????????? one++;??????????? if(one>=3){?????????? ??? ?System.out.println( scores[i]);??????????? }?????????? return score;??????? }??? }???
查看完整描述

1 回答

?
一條小咸魚

TA貢獻457條經(jīng)驗 獲得超255個贊

????public?int[]?nums(int[]?scores)?{
????????int?one?=?0;
????????for?(int?i?=?0;?i?<?scores.length;?i++)?{

????????????if?(scores[i]?<?0?||?scores[i]?>?100)?{
????????????????continue;
????????????}
????????????one++;
????????????if?(one?>=?3)?{
????????????????System.out.println(scores[i]);
????????????}
????????}
????????return?scores;
????}

其實你這個程序邏輯有問題,你隨意加一個0-100的數(shù),就知道不對了,應(yīng)該反向輸出

這是我寫的,你可以參考下

import?java.util.Arrays;

public?class?HelloWorld?{


????//?完成?main?方法

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

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

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

		hello.scoSortAndPrint(scores);


	}


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

	public?void?scoSortAndPrint(int[]?score)?{

		Arrays.sort(score);

		int?count?=?0;

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

		for?(int?i?=?score.length?-?1;?i?>=?0?&&?count?<3;?i--)?{

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

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

				count++;


			}

		}

	}

}


查看完整回答
反對 回復(fù) 2016-03-06
  • 1 回答
  • 0 關(guān)注
  • 1385 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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