總是有一個錯誤,求大神解答。
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.topThree(scores);
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ??
? ??
? ? public void topThree(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? int n=0;
? ? for(int i = scores.length-1; i>=0;i--){
? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? n++;
? ? if(n>3){
? ? ? ? break;
? ? ? ? }
? ? }
? ? System.out.println(scores[i]); ??
? ?
? ? }
? ??
}
}
報錯:/85/1598/BhJF/HelloWorld.java:32: error: class, interface, or enum expected
}
^
1 error
2016-03-13
你自定義方法里大括號有問題
應將topthree方法中System.out.println前的大括號去掉