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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求java大神解答

求java大神解答

釗兄兄4281648 2017-09-16 20:48:06
package imooc;import java.util.Arrays;public class HelloWorld {?public static void main(String[] args) {??HelloWorld helloworld = new HelloWorld();??int[]scores = new int[] {23,34,45,21,119,-223,72};??helloworld.Sort(scores); //報錯?}?public void Sort(int[]scores) {??Arrays.sort(scores);??int[]score = new int[3];??int count=0;??for(int i=0;i<scores.length;i++) {???if(scores[i]>100) {????continue;???}???else {????if(count>3) {?????break;????}????else {???????score[count] = scores[i];? //報錯?????count++;????}???}??}??System.out.println(Arrays.toString(score));?}}為什么會報錯 一臉懵逼
查看完整描述

1 回答

已采納
?
慕婉清0_郁亂我心

TA貢獻(xiàn)22條經(jīng)驗(yàn) 獲得超43個贊

在 if (cont>3) 這里 是可以的 但是你定義的 數(shù)組 ? 為int[] score = new int[3]; 所以 索引最高為2

但是你在??score[count] = scores[i]; ? 這里的 時候 count 的值 是可以 取到 3 的. 所以 就會報

java.lang.ArrayIndexOutOfBoundsException????? ? 數(shù)組下標(biāo)越界 異常

注意:?

????????數(shù)組的 下標(biāo)最大 為 數(shù)組長度(個數(shù)) 減一, 因?yàn)?index 是從 0 開始的!

查看完整回答
1 反對 回復(fù) 2017-09-16
  • 1 回答
  • 0 關(guān)注
  • 1377 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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