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

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

求大神指點錯在哪

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("考試成績的前三名為:");

? ? ? ? int[] qiansan =hello.score(scores);

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

? ? ? ? {

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

? ? ? ? }

? ? }

? ??

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

? ? public int score(int[] scores)

? ? {

? ? ? ? Arrays.sort(scores);

? ? ? ? int n=1;

? ? ? ? int[] num=new int[3];

? ? ? ? for(int i=scores.length-1;i>=0;i++)

? ? ? ? {

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

? ? ? ? ? ? continue;

? ? ? ? ? ? if(n<=3)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? num[n-1]=scores[i];

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? break;

? ? ? ? }

? ? ? ? return num;

? ? }

}


正在回答

3 回答

方法錯誤,int[] qiansan =hello.score(scores);這句都是多余的,很多代碼都是錯的哦,給你參考我的。A1是我自己取的,就是HelloWorld..

package?com.A;
import?java.util.Arrays;

public?class?A1?{
?public?static?void?main(String[]?ages){
	?int[]?scores?=?{89,-23,64,91,119,52,73};
	?System.out.println("成績的前三名為:");
	?A1?Top3?=?new?A1();
	?Top3.showTop3(scores);
?}
?public?void?showTop3(int[]?scores){
??Arrays.sort(scores);
??int?num?=?0;
???for(int?i?=?scores.length?-?1?;?i?>=?0?;?i--){
	??if(?scores[i]?<?0?||?scores[i]?>?100?){
	??continue;
???}
???num++;
???if(?num?>?3?){
	??break;
???}
??System.out.println(scores[i]);
???}
?}
}
0 回復 有任何疑惑可以回復我~
#1

baekai 提問者

非常感謝!
2016-10-20 回復 有任何疑惑可以回復我~

編譯錯誤還是運行錯誤還是邏輯錯誤?

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

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("考試成績的前三名為:");

??????? int[] qiansan =hello.score(scores);

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

??????? {

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

??????? }

??? }

???

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

??? public int[] score(int[] scores)

??? {

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

??????? int n=1;

??????? int[] num=new int[3];

??????? for(int i=scores.length-1;i>=0;i--)

??????? {

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

??????????? continue;

??????????? if(n<=3)

??????????? {

??????????????? num[n-1]=scores[i];
??????????????? n++;

??????????? }

??????????? else

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

??????? }

??????? return num;

??? }

}

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

舉報

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

0基礎萌新入門第一課,從Java環境搭建、工具使用、基礎語法開始

進入課程

求大神指點錯在哪

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

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

幫助反饋 APP下載

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

公眾號

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