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

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

借書(shū)系統(tǒng),第二步輸入書(shū)籍名稱(chēng)老是錯(cuò)誤,大神求解


import java.util.Scanner;


public class TakeBook {

public static void main(String[] args) {

TakeBook test = new TakeBook();

test.select();

}


public void select() {

String[] bookName = { "Java", "python", "C++" };

System.out.println("請(qǐng)輸入對(duì)應(yīng)的命令查找書(shū)籍:\n1--按編號(hào)查找書(shū)籍\n2--按照書(shū)籍名稱(chēng)查找書(shū)籍");

Scanner input = new Scanner(System.in);

try {

int order = input.nextInt();

if (order != 1 && order != 2) {

throw new Exception();

} else {

if (order == 1) {

System.out.println("請(qǐng)輸入書(shū)籍編號(hào):");

try {

int bookNum = input.nextInt();

if (bookNum < 1 || bookNum > bookName.length) {

throw new Exception();

} else {

System.out.println("您的書(shū)籍為:" + bookName[bookNum - 1]);

}

} catch (Exception e) {

System.out.println("請(qǐng)輸入正確的編號(hào)!\n");

throw new Exception();

}

}

}

if (order == 2) {

System.out.println("請(qǐng)輸入書(shū)籍名稱(chēng):");

try {

String inputName = input.next();

for (int i = 0; i <= bookName.length - 1; i++) {

if (inputName.equals(bookName[i])) {

System.out.println("您的書(shū)籍為:" + bookName[i]);

} else {

throw new Exception();

}

}


} catch (Exception e) {

System.out.println("您輸入的書(shū)籍不存在,請(qǐng)重新輸入\n");

throw new Exception();

}

}

} catch (Exception e) {

System.out.println("---請(qǐng)按照提示輸入正確信息---");

select();

}

}

}


正在回答

3 回答

String inputName = input.next();

改成

String inputName = input.nextLine();試試看

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

System.out.println("您的書(shū)籍為:" + bookName[i]);加break;跳出循環(huán)。else寫(xiě)在循環(huán)外試試?


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

具體是什么類(lèi)型的錯(cuò)誤?是你所輸入的書(shū)名找不到還是其他?

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

舉報(bào)

0/150
提交
取消

借書(shū)系統(tǒng),第二步輸入書(shū)籍名稱(chēng)老是錯(cuò)誤,大神求解

我要回答 關(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)