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

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

有沒(méi)有高手幫我看看代碼怎么運(yùn)行不起!

package?immoc.com.trycatch;
public?class?Test?{
/*
?*?拋出?數(shù)組越界和算術(shù)異常
?*/
?public?void?Test1(int?x)?throws?ArrayIndexOutOfBoundsException,ArithmeticException{
?????System.out.println(x);
?????if(x?==?0){
?????????System.out.println("沒(méi)有異常");
?????????return;
?????}
?????//數(shù)據(jù)越界異常
?????else?if?(x?==?1){
?????????int[]?a?=?new?int[3];
??????????a[3]?=?5;
?????}
?????//算術(shù)異常
?????else?if?(x?==?2){
?????????int?i?=?0;
?????????int?j?=?5/0;
?????}
?}
}

package immoc.com.trycatch;
public class ExceptionInital {
?/**
? * @param args
? */

public static void main(String[] args){
?//創(chuàng)建對(duì)象
??? ExceptionInital object = new ExceptionInital();
??? // 調(diào)用會(huì)拋出異常的方法,用try-catch塊
??? try{
??????? object.Test1(0);
??? }catch(Exception e){
??????? System.out.println(e);
??? }
??? // 數(shù)組越界異常
??? try{
??????? object.Test1(1);
??? }catch (ArrayIndexOutOfBoundsException e) {
??????? System.out.println("數(shù)組越界異常:"+e);
??? }
??? // 算術(shù)異常
??? try{
??????? object.Test1(2);
??? }catch(ArithmeticException e){
??????? System.out.println("算術(shù)異常:"+e);
??? }
??? //使用 throw 拋出異常(可以拋出異常對(duì)象,也可以拋出異常對(duì)象的引用)
??? try{
??????? ArrayIndexOutOfBoundsException? exception = new ArrayIndexOutOfBoundsException();
??????? throw exception;//new ArrayIndexOutOfBoundsException();
??? }catch(ArrayIndexOutOfBoundsException e){
??????? System.out.println("thorw拋出異常:"+e);
??? }

}



正在回答

2 回答

public static void main(Strring[] args),這里多了個(gè)r,應(yīng)該是String[]

ExceptionInital類中沒(méi)有定義test1(),自己也是小白,還不知道怎么解決

希望能幫到你

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

kk求知者 提問(wèn)者

我腦袋搞昏了 我對(duì)象創(chuàng)建錯(cuò)了?。。?!
2017-12-18 回復(fù) 有任何疑惑可以回復(fù)我~
#2

kk求知者 提問(wèn)者

ExceptionInital類,我這個(gè)寫的測(cè)試類 創(chuàng)建Method對(duì)象 調(diào)用Test中的Test1方法。。
2017-12-18 回復(fù) 有任何疑惑可以回復(fù)我~

你自己放Eclipse里面看看

public static void main(Strring[] args)這里錯(cuò)了

而且你要調(diào)用的Test1方法在Test類里面。所以object的類型應(yīng)該是Test

其他的你在自己看吧。

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

Simenzz

而且我覺(jué)得throws里面至少要throw出異常 我也剛開(kāi)始學(xué),有什么問(wèn)題請(qǐng)指出。
2017-12-18 回復(fù) 有任何疑惑可以回復(fù)我~
#2

kk求知者 提問(wèn)者 回復(fù) Simenzz

我敲代碼敲昏了,我對(duì)象創(chuàng)建錯(cuò)了!應(yīng)該是Method object=new Method();
2017-12-18 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

有沒(méi)有高手幫我看看代碼怎么運(yùn)行不起!

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

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

幫助反饋 APP下載

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

公眾號(hào)

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