第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

請問 這樣寫錯在哪里?謝謝!

package com.Java;

import java.util.Arrays;

public class HelloWorld {
?
?public static void main(String[] args) {
??
??int[] scores = {89 , -23 , 64 , 91 , 119 , 52 , 73};
??
??System.out.println("成績前三名為:");
??
??HelloWorld hello = new HelloWorld();
??
??hello.sortAndPrint(scores);
???
?}
?
?public void sortAndPrint(int[] scores){
??
?Arrays.sort(scores);
?
?int num=0;
?
?for (int i=scores.length ;i>=0;i--){
??
??if (scores[i]>0 && scores[i]<=100){
???
???System.out.println(scores[i]);
????
???num++;
???
???} ?else?{
???
???continue;
???
???}
??
??if (num==3){break;}
??
??}
??
?}
?
?
}

運行結(jié)果


成績前三名為:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
?at com.Java.HelloWorld.sortAndPrint(HelloWorld.java:27)
?at com.Java.HelloWorld.main(HelloWorld.java:15)

正在回答

3 回答

下標(biāo)越界


0 回復(fù) 有任何疑惑可以回復(fù)我~

length-1

0 回復(fù) 有任何疑惑可以回復(fù)我~

找到錯誤了,當(dāng)數(shù)組有7個數(shù)的時候,scores.length=7,而數(shù)組中最高分的 數(shù)是 scores[6],

所以 int i=scores.length-1


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

請問 這樣寫錯在哪里?謝謝!

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號