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

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

感覺寫得不太好,請大佬們多多指教

package?borrow_books;
import?java.util.Scanner;
import?java.util.InputMismatchException;

public?class?Test?{
????int?command;	
????String?inName;	
????int?inNum;?	
????Scanner?input?=?new?Scanner(System.in);	
????Book[]?books?=?{new?Book("數(shù)據(jù)結構",?1),?new?Book("高數(shù)",?2)};
????		
????public?static?void?main(String[]?args)?{
????????while(true)?{
????????????Test?t?=?new?Test();
????????????t.inputCommand();
????????????if(t.command?==?1)?{
????????????????t.inputName();
????????????}else?if(t.command?==?2){
????????????????t.inputNumber();
????????????}
????????}
????}
????public?void?inputCommand()?{
????????try?{
????????????System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號查找圖書");
????????????command?=?input.nextInt();
????????????if((command?!=?1)?&&?(command?!=?2))?{
????????????????throw?new?ErrorCommandException();
????????????}
????????}catch(InputMismatchException?ie)?{
????????????ErrorCommandException?ee?=?new?ErrorCommandException();
????????????System.out.println(ee.getMessage());
????????}catch(ErrorCommandException?ee)?{
????????????System.out.println(ee.getMessage());
????????}
????}
????public?void?inputName()?{		
????????try?{			
????????????System.out.println("輸入圖書名稱");		
????????????inName?=?input.next();	
????????????for(int?i?=?0;?i?<?books.length;?i++)?{			
????????????????if(inName.equals(books[i].name))?{			
?????????????	????books[i].showBookName();					
?????????????	????return;				
?????????????	}			
????????????}			
????????????throw?new?BooknotExistException();		
????????}catch(Exception?e)?{		
????????????System.out.println(e.getMessage());		
????????}	
????}
????public?void?inputNumber()?{
????????while(true)?{			
????????????try?{			
????????????????System.out.println("輸入圖書序號");			
????????????????inNum?=?input.nextInt();				
????????????????for(int?i?=?0;?i?<?books.length;?i++)?{					
????????????????????if(inNum?==?books[i].number)?{						
????????????????????????books[i].showBookName();						
????????????????????????return;					
????????????????????}
????????????????}				
????????????????throw?new?BooknotExistException();			
????????????}catch(InputMismatchException?ie)?{				
????????????????input.nextLine();				
????????????????ErrorCommandException?ee?=?new?ErrorCommandException();				
????????????????System.out.println(ee.getMessage());			
????????????}catch(BooknotExistException?be)?{				
????????????????System.out.println(be.getMessage());				
????????????????return;			
????????????}		
????????}	
????}
}
package?borrow_books;

public?class?ErrorCommandException?extends?Exception?{	
????public?ErrorCommandException()?{		
????????super("命令輸入錯誤!請根據(jù)提示輸入數(shù)字命令!");	
????}
}
package?borrow_books;

public?class?BooknotExistException?extends?Exception?{	
????public?BooknotExistException()?{		
????????super("圖書不存在!");	
????}
}
package?borrow_books;

public?class?Book?{	
????String?name;	
????int?number;		
????
????public?Book(String?name,?int?number)?{	
????????this.name?=?name;	
????????this.number?=?number;	
????}
????
????public?void?showBookName()?{		
????????System.out.println("book:"+name);
????}
}


正在回答

4 回答

感覺上就只有你編寫的代碼是方便的,我挺喜歡的。

1 回復 有任何疑惑可以回復我~
#1

慕神6168092 提問者

哈哈,謝謝
2020-08-27 回復 有任何疑惑可以回復我~

你這有一個bug,輸入1至3選擇時,如果輸入字母會報錯的

1 回復 有任何疑惑可以回復我~
#1

qq_慕絲4346553

看錯啦
2021-08-15 回復 有任何疑惑可以回復我~

謝謝分享,學習了~

0 回復 有任何疑惑可以回復我~

思路清晰,代碼簡潔,已參考,謝謝樓主。

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

感覺寫得不太好,請大佬們多多指教

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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