這里面哪錯了調了好幾遍老顯示main里面有錯
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? int []scores={89,-23,64,91,119,52,73};
? ? HelloWorld hello=new HelloWorld();
? ? hello.top3(scores);
? ? ? ??
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void top3(int []scores)
? ? {
? ? ? ? int num=0;
? ? ? ? Arrays.sort(scores);
? ? ? ? for(int i=scores.length;i>=0;i--)
? ? ? ? {
? ? ? ? ? ? if(scores[i]>100||scores[i]<0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? num++;
? ? ? ? ? ? if(num>3)
? ? ? ? ? ? {
? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? }
? ? ? ??
? ? }
? ??
? ??
}
2017-08-11
數組變量越界 i 從length-1開始才對