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

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

為什么輸入存在的圖書名也是執(zhí)行異常?求大蛇指點(diǎn)

public class borrowBooks {


public static void main(String[] args) {

// 調(diào)用select方法

borrowBooks Select = new borrowBooks();

Select.select();

}

/**

*?

*/

public void select() {

String[][] bookList=new String[][] {{"1","水滸傳"},{"2","紅樓夢(mèng)"},{"3","三國(guó)演義"}};

//String[] bookList = new String[] {"java基礎(chǔ)","水滸傳","紅樓夢(mèng)","西游記","數(shù)據(jù)結(jié)構(gòu)"};?

System.out.println("輸入命令:1-按照?qǐng)D書名稱查詢 ? 2-按照?qǐng)D書編號(hào)查詢");

Scanner input = new Scanner(System.in);

int num = input.nextInt();

try {

if(num==1) {

System.out.println("請(qǐng)輸入您要查找的圖書名稱:");

Scanner input1 = new Scanner(System.in);

String bookName=input1.nextLine();

//一維數(shù)組

/* boolean t=Arrays.asList(bookList).contains(bookName);

if(t) {

System.out.println("您輸入的圖書"+bookName+"存在!");

}else {

throw new NobookException();

}*/

//二維數(shù)組

for(String[] bookname:bookList) {

for(String book:bookname) {

if(book.equals(bookName)) {

System.out.println("您輸入的圖書"+book+"存在!");

}else ?{

throw new NobookException();

}

}

}

}else if(num==2) {

System.out.println("請(qǐng)輸入您要查找的圖書編號(hào)");

Scanner input2 = new Scanner(System.in);

int bookNum=input2.nextInt();

if(bookNum>=1&&bookNum<=bookList.length) {

System.out.println("您查找的圖書名稱為"+bookList[bookNum-1]);

}else {

throw new NobookException();

}

}else {

throw new CommandException();

}

}catch (NobookException e) {

// TODO: handle exception

System.out.println("您輸入的圖書不存在!請(qǐng)重新輸入");

select();

}catch (CommandException e) {

// TODO: handle exception

System.out.println("您輸入的命令有誤,請(qǐng)重新輸入");

select();

}

}

}


正在回答

1 回答

以下語(yǔ)句執(zhí)行多次,書名不一樣時(shí),就拋出異常。

if(book.equals(bookName)) {

System.out.println("您輸入的圖書"+book+"存在!");

}else ?{

throw new NobookException();

}


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

xinzhongdexingxing

這個(gè)可以打斷點(diǎn)排查問(wèn)題的。在拋出異常的地方打斷點(diǎn),每次進(jìn)斷點(diǎn)看下是什么樣的數(shù)據(jù)情況,為什么進(jìn)斷點(diǎn),就可以比較快的分析出原因了。
2019-03-18 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么輸入存在的圖書名也是執(zhí)行異常?求大蛇指點(diǎ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)