亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

無返回值的方法我的代碼可以跑,可我想做一個帶返回值類型為數組類型的,就不行,求教是為什么?代碼如下

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};
??????? System.out.println("考試成績的前三名為:");
??????? hello.output(Scores);?
??? }
???
??? //定義方法完成成績排序并輸出前三名的功能
??? public int[] output(int Scores[]){
??????? int num = 0;
?????? Arrays.sort(Scores);
?????? for(int i=Scores.length-1;i>=0;i--){
?????????? if(Scores[i]>100||Scores[i]<0){
?????????????? continue;
?????????? }
?????????? num++;
?????? if(num>3){
?????????? break;
??????? }
?????? System.out.println(Scores[i]);
?????? }
??? }
??? return Scores[];
}

正在回答

2 回答

return Scores;

0 回復 有任何疑惑可以回復我~
//?引入Arrays類
import?java.util.Arrays;

public?class?HelloWorld?{
????public?static?void?main(String[]?args)?{
????????HelloWorld?hello?=?new?HelloWorld();
????????int?[]?Scores?=?{89,-23,64,91,119,52,73};
????????int?[]?scores?=?hello.output(Scores);
????????System.out.println("考試成績的前三名為:"+Arrays.toString(scores));
????}

????//定義方法完成成績排序并輸出前三名的功能
????public?int[]?output(int?Scores[]){
????????Arrays.sort(Scores);
????????int[]?score?=?new?int[Scores.length];
????????int?j?=?0;
????????for(int?i=Scores.length-1;i>=0;i--){
????????????if(Scores[i]<0?||?Scores[i]>100){
????????????????continue;
????????????}
????????????score[j]?=?Scores[i];
????????????j++;
????????}
????????int[]?scores?=?new?int[3];
????????for?(int?i=0;i<3;i++){
????????????scores[i]?=?score[i];
????????}
????????return?scores;
????}
}


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

舉報

0/150
提交
取消

無返回值的方法我的代碼可以跑,可我想做一個帶返回值類型為數組類型的,就不行,求教是為什么?代碼如下

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號