指令輸入正常,程序沒問題。但是指令測(cè)試bug就跳過了怎么辦,求大佬指點(diǎn)
package?com.test.trycatch; import?java.util.*; public?class?TryTest?{ ???? ????static?Scanner?sin?=?new?Scanner(System.in); ????static?BookFindTry[]?books?=?{new?storyBook(1,"西游記"),new?storyBook(2,"紅樓夢(mèng)"),new?storyBook(4,"水滸傳"),new?juvenileBook(49,"三體")}; ???? ????public?static?void?main(String[]?args)?{ ????????try?{ ????????????try?{ ????????????????TryTest.show(); ????????????}?catch?(InputMismatchException?e)?{ ????????????????/*e.printStackTrace();*/ ????????????????System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令!"); ????????????????TryTest.show(); ????????????} ????????}?catch?(Exception?e)?{ ????????????????e.printStackTrace(); ????????????????System.out.println("抱歉,您查詢的圖書不存在!或已被其它同學(xué)借走!"); ????????????????TryTest.show(); ????????} ????} ???? ????private?static?void?show()?{ ????????System.out.println("輸入命令查找圖書:1-按照名稱查找圖書;2-按照序號(hào)查找圖書"); ????????int?intput?=?sin.nextInt(); ????????if(intput==1){ ????????????System.out.println("請(qǐng)輸入書名:"); ????????????String?iputbookname?=?sin.next(); ????????????for(int?i=0;i<books.length;i++){ ????????????????if(iputbookname.equals(books[i].bookName)){ ????????????????????System.out.println("恭喜您借書《"+books[i].bookName+"》成功!"?); ????????????????}else?{ ????????????????}???? ????????????} ????????}else?if?(intput==2)?{ ????????????System.out.println("請(qǐng)輸入序號(hào):"); ????????????int?iputbookid?=?sin.nextInt(); ????????????for(int?i=0;i<books.length;i++){ ????????????????if(iputbookid==books[i].bookId){ ????????????????????System.out.println("恭喜您借書《"+books[i].bookName ????????????????????????????+"》成功!"?); ????????????????}else?{ ????????????????}???? ????????????} ????????} ????} }
這是正確運(yùn)行程序的結(jié)果圖,其中每次的輸入指令處都有一個(gè)try…catch判斷是否輸入正確,不正確澤返回上一步驟,重新輸入。
2019-07-22
開頭就錯(cuò)了吧? ? 靜態(tài)修飾符 修飾了變量? ?over
2019-07-21
能再詳細(xì)描述一下你想實(shí)現(xiàn)的效果嗎