最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

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

交作業(yè)---模擬結(jié)束系統(tǒng)

public?class?BorrowBook?{
????public?static?String[]?books?=?{"第一行代碼",?"thinking?in?java",?"安卓探索藝術(shù)"};
????public?static?Scanner?sc;
????public?static?boolean?flag?=?true;
????public?static?boolean?isIndexOrName?=?false;

????public?static?void?main(String[]?args)?{
????????System.out.println("***歡迎來到模擬圖書系統(tǒng)***");
????????System.out.println("請輸入您要查找圖書的方式:1.按圖書序號查找"?+?"\t"?+?"2.按圖書名稱查找");
????????System.out.println("請輸入一個有效查找方式:");
????????find2IndexOrName();
????}

????private?static?void?find2IndexOrName()?{
????????sc?=?new?Scanner(System.in);
????????int?input?=?sc.nextInt();
????????try?{
????????????if?(1?==?input)?{
????????????????System.out.println("請輸入有效圖書序號:");
????????????????int?index?=?sc.nextInt();
????????????????find2Index(index);
????????????}?else?if?(2?==?input)?{
????????????????System.out.println("請輸入正確的書名:");
????????????????String?name?=?sc.next();
????????????????find2Name(name);
????????????}?else?{
????????????????throw?new?Exception();
????????????}
????????}?catch?(Exception?e)?{
????????????System.out.println("請輸入正確指令:");
????????????find2IndexOrName();
????????}
????}

????public?static?void?find2Name(String?name)?{
????????isIndexOrName?=?true;
????????try?{
????????????for?(int?i?=?0;?i?<?books.length;?i++)?{
????????????????if?(name.equals(books[i]))?{
????????????????????showBook(name,?i);
????????????????????break;
????????????????}?else?{
????????????????????throw?new?Exception();
????????????????}
????????????}
????????}?catch?(Exception?e)?{
????????????System.out.println("圖書不存在,請重新輸入:");
????????????String?s?=?sc.next();
????????????find2Name(s);
????????}
????}

????public?static?void?find2Index(int?index)?{
????????isIndexOrName?=?false;
????????try?{
????????????for?(int?i?=?0;?i?<?books.length;?i++)?{
????????????????if?(index?==?i)?{
????????????????????showBook(index);
????????????????????break;
????????????????}?else?if?(index?>?2)?{
????????????????????throw?new?Exception();
????????????????}
????????????}
????????}?catch?(Exception?e)?{
????????????System.out.println("圖書不存在,請重新輸入:");
????????????int?i?=?sc.nextInt();
????????????find2Index(i);
????????}
????}

????/**
?????*?通過書名查找圖書
?????*
?????*?@param?name??書名
?????*?@param?index?書名對應(yīng)的下標(biāo)
?????*/
????private?static?void?showBook(String?name,?int?index)?{
????????System.out.println("***查找到以下內(nèi)容***");
????????if?(books[index].equals(name))?{
????????????System.out.println("第一行代碼");
????????}?else?if?(books[index].equals(name))?{
????????????System.out.println("thinking?in?java");
????????}?else?if?(books[index].equals(name))?{
????????????System.out.println("安卓探索藝術(shù)");
????????}
????????System.out.println("***確定借閱嗎?(Y/N)***");
????????String?s?=?sc.next();
????????isBorrow(s);
????}

????/**
?????*?通過圖書序號查找
?????*
?????*?@param?index?圖書的序號
?????*/
????private?static?void?showBook(int?index)?{
????????System.out.println("***查找到以下內(nèi)容***");
????????System.out.println(books[index]);
????????System.out.println("確認(rèn)借閱本書嗎?(Y/N)");
????????String?s?=?sc.next();
????????isBorrow(s);
????}

????private?static?void?isBorrow(String?s)?{
????????if?(s.equals("Y")?||?s.equals("y"))?{
????????????System.out.println("恭喜您借閱成功");
????????}?else?if?(s.equals("N")?||?s.equals("n"))?{
????????????System.out.println("您以取消操作!請重新操作!");
????????????if?(flag)?{
????????????????System.out.println("請輸入一個有效查找方式:"+"\n"+"1.按序號查找"+"\n"+"2.按書名查找");
????????????????find2IndexOrName();
????????????}
????????}
????}
}


正在回答

1 回答

都沒有用到多重catch

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

慕標(biāo)5588573 提問者

你把簡單的問題復(fù)雜化了,這并不符合面向?qū)ο蟮木幊趟枷?/div>
2019-02-25 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

交作業(yè)---模擬結(jié)束系統(tǒng)

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

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

幫助反饋 APP下載

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

公眾號

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