各位大佬,能幫我看看哪錯了嗎?
package com.imooc;
import java.util.Arrays;
public class HelloWorld {
?
?public static void main(String[] args) {
??HelloWorld hello=new HelloWorld();
??int[]scores={89,-23,64,91,119,52,73};
??System.out.println();
??hello.showTop(scores);
??
??
?}
?public void showTop(int[]scores){
??Arrays.sort(scores);
??for(int i=scores.length-1;i>=0;i++){
???if(i<scores.length-3){
????break;
???}
???System.out.println(scores[i]);
??}
??
2020-02-19
首先 倒序遍歷 應(yīng)該用 i-- 不然你循環(huán)里條件 if(i<scores.length-3) 是一直成立的,而且 你輸出的時候會超過數(shù)組長度
其次 不能用break 應(yīng)該用continue