課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級(jí)版
一開始想用待返回值的,一看答案都是不帶返回值的
2019-08-11
源自:Java入門第一季(IDEA工具)升級(jí)版 7-1
正在回答
import java.util.Arrays;public class HelloWorld {??? ??? //完成 main 方法??? public static void main(String[] args) {??????? HelloWorld hello = new HelloWorld();??????? int[] scores = {89 , -23 , 64 , 91 , 119 , 52 , 73};??????? int[] firstScores = hello.firstScore(scores);??????? System.out.println("考試成績(jī)的前三名為:");??????? for(int a:firstScores)??????????? System.out.println(a);??? }??? ??? //定義方法完成成績(jī)排序并輸出前三名的功能??? public int[] firstScore(int[] scores){??????? int[] firstScores = new int[3];??????? int time=0;??????? Arrays.sort(scores);??????? for(int i=scores.length-1;i>=0;i--){??????????? if(scores[i]<=100&&scores[i]>=0){??????????????? firstScores[time]=scores[i];??????????????? time++;??????????????? if(time==3)??????????????????? break;??????????? }??????? }??????? return firstScores;??? }}
只能返回一個(gè)數(shù)
舉報(bào)
0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語法開始
4 回答為什么用帶參帶返回值的方法不行?
1 回答為什么要用帶參無返回值的方法
1 回答方法何時(shí)帶返回值
3 回答關(guān)于方法返回值的問題
3 回答如果這題用帶返回值的方法改怎么編???
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2019-08-13
import java.util.Arrays;
public class HelloWorld {
???
??? //完成 main 方法
??? public static void main(String[] args) {
??????? HelloWorld hello = new HelloWorld();
??????? int[] scores = {89 , -23 , 64 , 91 , 119 , 52 , 73};
??????? int[] firstScores = hello.firstScore(scores);
??????? System.out.println("考試成績(jī)的前三名為:");
??????? for(int a:firstScores)
??????????? System.out.println(a);
??? }
???
??? //定義方法完成成績(jī)排序并輸出前三名的功能
??? public int[] firstScore(int[] scores){
??????? int[] firstScores = new int[3];
??????? int time=0;
??????? Arrays.sort(scores);
??????? for(int i=scores.length-1;i>=0;i--){
??????????? if(scores[i]<=100&&scores[i]>=0){
??????????????? firstScores[time]=scores[i];
??????????????? time++;
??????????????? if(time==3)
??????????????????? break;
??????????? }
??????? }
??????? return firstScores;
??? }
}
2019-08-12
只能返回一個(gè)數(shù)