運(yùn)行錯(cuò)誤 錯(cuò)誤:例外;錯(cuò)誤行9 16
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? int[] score={89,-23,64,91,119,52,73};
? ? ? ? hello.sort(score);
? ? ? ? ?//定義方法完成成績(jī)排序并輸出前三名的功能
? ? ? ??
? ? }
? ? public void sort(int[] score){
? ? Arrays.sort(score);
? ? ? ? for(int i =score.length;i>i-3;i--){
? ? ? ? System.out.println(score[i]);
? ? ? ? }
? ? }
}
2018-05-18
方法里面的for循環(huán)應(yīng)該從數(shù)組最后一個(gè)開(kāi)始遍歷,也就是初始化int i = score.length -1; for循環(huán)內(nèi)容如下: