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

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

可以運(yùn)行,但是為什么說Systen.out.println((i+1)+"."+carsForRent[i].toString());出現(xiàn)異常?

public class Rent {

public static void main(String[] args)throws FileNotFoundException {

Car car = new Car();

Car[] carsForRent = {new Manned("奧迪A4",500,4),new Manned("馬自達(dá)6",400,4),new MannedTruck("皮卡雪6",450,4,2),new Manned("金龍",800,20),new Truck("松花江",400,4),new Truck("依維柯",1000,20)};

System.out.println("歡迎使用答答租車系統(tǒng):");

System.out.println("您是否要租車:1是 0否");

Scanner scan = new Scanner(System.in);?

int input = scan.nextInt();

if(input == 1){

System.out.println("您可租車的類型及其價(jià)目表:");

System.out.println("序號 \t\t汽車名稱 \t\t租金 \t\t容量\t");


for(int i=0;i<=carsForRent.length;i++){

System.out.println((i+1) +". " + carsForRent[i].toString());

}


}

}

}

}


正在回答

2 回答

樓上說的對,你想想最后一次是不是i=6,因?yàn)槟鉩arForRent[i]下標(biāo)是從0開始的,長度是6,,最后一次是carForRent[6],數(shù)組下標(biāo)越界了,ArraysIndexOutOfBoundException

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

<= 改成 < ,因?yàn)?,carsForRent最后一個(gè)數(shù)據(jù)的index是carsForRent.length - 1

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

舉報(bào)

0/150
提交
取消

可以運(yùn)行,但是為什么說Systen.out.println((i+1)+"."+carsForRent[i].toString());出現(xiàn)異常?

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

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

幫助反饋 APP下載

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

公眾號

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