求大神指點(diǎn)錯(cuò)在哪
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("考試成績(jī)的前三名為:");
? ? ? ? int[] qiansan =hello.score(scores);
? ? ? ? for(int i=0;i<qiansan.length;i++)
? ? ? ? {
? ? ? ? ? System.out.println(qiansan[i]);
? ? ? ? }
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? 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;
? ? }
}
2016-10-18
方法錯(cuò)誤,int[] qiansan =hello.score(scores);這句都是多余的,很多代碼都是錯(cuò)的哦,給你參考我的。A1是我自己取的,就是HelloWorld..
2016-10-18
編譯錯(cuò)誤還是運(yùn)行錯(cuò)誤還是邏輯錯(cuò)誤?
2016-10-18
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("考試成績(jī)的前三名為:");
??????? int[] qiansan =hello.score(scores);
??????? for(int i=0;i<qiansan.length;i++)
??????? {
????????? System.out.println(qiansan[i]);
??????? }
??? }
???
??? //定義方法完成成績(jī)排序并輸出前三名的功能
??? 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;
??? }
}