我是這樣寫的,為什么有錯呢,說是 Array.sort(scores);這里有錯,可以請你們幫我看一下嗎
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? int[] scores ={89,-23,64,91,119,52,73};
? ? ? ?System.out.println("輸出考試成績前三名:");
? ? ? ?HelloWorld hello=new HelloWorld();
? ? ? ?hello.getThreeStu(scores);
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void getThreeStu( int[] scores)
? ? {
? ? ? ? int count=0;
? ? ? ? Array.sort(scores);
? ? ? ? for(int i=scores.length-1;i>=0;i--)
? ? ? ? {
? ? ? ? ? ? while(count<3)
? ? ? ? ? ?{?
? ? ? ? ? ? if(scores[i]>0)
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? count++;
? ? ? ? ? ?}
? ? ? ? }
? ??
? ? }
? ??
2017-07-19
Array.sort(scores);你沒有在Array后面加S
2017-07-17
我知道了!
import java.util.Arrays;
public class HelloWorld {
? ? ?//完成 main 方法
? ? public static void main(String[] args) {
? ? ? int[] scores ={89,-23,64,91,119,52,73};
? ? ? ?System.out.println("輸出考試成績前三名:");
? ? ? ?HelloWorld hello=new HelloWorld();
? ? ? ?hello.getThreeStu(scores); ? ?
? ? }
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void getThreeStu( int[] scores)
? ? {
? ? ? ? int count=0;
? ? ? ? Arrays.sort(scores); ??
? ? ? ? for(int i=scores.length-1;i>=0;i--)
? ? ? ? ?{ ?
? ? ? ? ? ? if(scores[i]>0&&count<3)
? ? ? ? ? ? {System.out.println(scores[i]);}
? ? ? ? ? ? ? count++; ?
? ? ? ? }
} ?
}