請問這是錯在哪了?代碼和運行結果如下。
package com.imooc;
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("前三名的成績?yōu)椋?);
? ? ? HelloWorld hello=new HelloWorld();
? ? ? hello.paixu(scores);
? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void paixu(int[] scores){
? ? ? ? int num=0;
? ? ? ? Arrays.sort(scores);
? ? ? ? for(int i=scores.length;i>=0;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? num++;
? ? ? ? ? ? if(num>=3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ??
? ? }
}
? ??
? ?
? ??
?
2018-08-02
length-1。下標等于長度減一,否則就下表越界啦。比如數組長度是6,你說她的下標是幾到幾
2018-08-02
2018-08-02