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

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

圖書查詢!

package?org.java.exception;
/**
?*?圖書不存在異常
?*?@author?1
?*
?*/
public?class?BookNotNullException??extends?Exception{
public?BookNotNullException()?{
}
public?BookNotNullException(String?message)?{
super(message);
}
}
package?org.java.exception;
/**
?*?指令輸入錯(cuò)誤異常;
?*?@author?1
?*
?*/
public?class?InstructNotException?extends?Exception{
public?InstructNotException()?{
}
public?InstructNotException(String?message)?{
????super(message);
}
}
package?org.java.exception;
import?java.util.Scanner;
public?class?BookTest?{
public?static?void?main(String[]?args){
String[]?str?=?{"語文","高數(shù)","英文","java","c","c++","jsp","PHP","Jquery","生物"};
Scanner?input?=?new?Scanner(System.in);
int?state=1;
System.out.println("歡迎進(jìn)入圖書查詢系統(tǒng)>>>>>>>");
do{
System.out.println("請(qǐng)選擇查詢條件?1按索引查詢?2按書名查詢");
???try?{
?????????int?a?=?input.nextInt();
?????????if(a==1){//輸入為1時(shí)
?????????????System.out.println("輸入1-10進(jìn)行查詢");
?????????????int?b?=?input.nextInt();
?????????try?{
?????????????if(b>0&&b<=10)?{
?????????????????System.out.println("book:"+str[b-1]);?
?????????????}else?{
?????????????????throw?new?BookNotNullException();
?????????}
????????}?catch?(BookNotNullException?e)?{
????????????System.out.println("圖書不存在異常");
????????}finally?{
????????????System.out.println("是否繼續(xù)查詢:1是?2否");
????????int?d?=?input.nextInt();
????????if(d==1)?{
????????state??=?1;?
????????}else?{
????????state?=0;
????????}
????}
?}else?if(a==2){//書名查詢時(shí)?不存在
?????????System.out.println("請(qǐng)輸入查詢的書名");
???????????String?book?=?input.next();
????????????try?{
??????????????int?c??=?findBookByName(book,str);
?????????????????if(c==0)?{
????????????????????????throw?new?BookNotNullException();?//拋出異常
?????????????????}
????????????????}?catch?(BookNotNullException?e)?{
????????????????????System.out.println("圖書不存在異常");
????????????????}finally?{
????????????????System.out.println("是否繼續(xù)查詢:1是?2否");
????????????????int?d?=?input.nextInt();
????????????????if(d==1)?{
????????????????state??=?1;?
????????????}else?{
????????state?=0;
????????}
}????
}else?{?
???throw?new?InstructNotException();//指令輸入錯(cuò)誤異常
?????}
?????}?catch?(InstructNotException?e?)?{
?????????System.out.println("指令輸入錯(cuò)誤異常");
????????????System.out.println("是否繼續(xù)查詢:1是?2否");
????????????int?d?=?input.nextInt();
????????if(d==1)?{
????????????state??=?1;?
????????}else?{
????????????state?=0;
????????}
????????}
}while(state!=0);
System.out.println("結(jié)束查詢");
}?
public?static?int?findBookByName(String?book,String[]?str)?{
for(int?i=0;i<str.length;i++)?{
?if(book.equals(str[i]))?{
?System.out.println("book:"+str[i]);
?return?1;
?}
?}??
return?0;
}
}


正在回答

2 回答

?throw?new?BookNotNullException();

請(qǐng)問拋這個(gè)異常的時(shí)候,不需要在方法頭進(jìn)行聲明嗎?

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

破壁_沖沖沖刺

額。。。因?yàn)閏atch了。。。。請(qǐng)無視我的問題。。。
2018-10-14 回復(fù) 有任何疑惑可以回復(fù)我~

試一下把查詢條件寫成函數(shù)

public?void?menu?(){
????System.out.println("請(qǐng)選擇查詢條件?1按索引查詢?2按書名查詢");
}

輸入錯(cuò)誤的時(shí)候?調(diào)用menu()返回選擇界面


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

why_ccc 提問者

感謝回復(fù)!理解你的意思,我用了下do while,謝謝
2018-09-18 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門第三季
  • 參與學(xué)習(xí)       409775    人
  • 解答問題       4546    個(gè)

Java中你必須懂得常用技能,不容錯(cuò)過的精彩,快來加入吧

進(jìn)入課程

圖書查詢!

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

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

幫助反饋 APP下載

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

公眾號(hào)

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