課程
/后端開發
/Java
/Java入門第一季(IDEA工具)升級版
一開始想用待返回值的,一看答案都是不帶返回值的
2019-08-11
源自:Java入門第一季(IDEA工具)升級版 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("考試成績的前三名為:");??????? for(int a:firstScores)??????????? System.out.println(a);??? }??? ??? //定義方法完成成績排序并輸出前三名的功能??? 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;??? }}
只能返回一個數
舉報
0基礎萌新入門第一課,從Java環境搭建、工具使用、基礎語法開始
4 回答為什么用帶參帶返回值的方法不行?
1 回答為什么要用帶參無返回值的方法
1 回答方法何時帶返回值
3 回答關于方法返回值的問題
3 回答如果這題用帶返回值的方法改怎么編啊?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
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("考試成績的前三名為:");
??????? for(int a:firstScores)
??????????? System.out.println(a);
??? }
???
??? //定義方法完成成績排序并輸出前三名的功能
??? 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
只能返回一個數