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

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

實(shí)現(xiàn)代碼如下

復(fù)制粘貼格式化,我還沒調(diào)試,如果有錯(cuò)誤可以回復(fù)分享一下。

package com.booksearch;


import java.util.*;


public class BookSearch {

public static void main(String[] args) {

String[] books = { "數(shù)據(jù)結(jié)構(gòu)", "高數(shù)", "論語" };

boolean flag = true;

while (flag) {

try {

System.out.println("輸入命令:1.按照名稱查圖書;2.按照序號(hào)查圖書");

Scanner input = new Scanner(System.in);

int cmdnum = input.nextInt();

if (cmdnum == 1) {

System.out.println("輸入圖書名稱:");

String name = input.next();

for (String book : books) {

if (book.equals(name)) {

System.out.println("book:" + book);

flag = false;

break;

}

}

if (flag) {

System.out.println("圖書不存在");

continue;

}

} else if (cmdnum == 2) {

System.out.println("輸入圖書序號(hào):");

int id = input.nextInt();

for (int i = 0; i < books.length; i++) {

if (id > 0 && id <= books.length) {

System.out.println("book:" + books[id - 1]);

flag = false;

break;

}

}

if (flag) {

System.out.println("圖書不存在");

continue;

}

}

} catch (Exception e) {

System.out.println("命令輸入錯(cuò)誤!請(qǐng)輸入數(shù)字命令!");

continue;

}

}

}

}


正在回答

1 回答

try catch沒用吧。。

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

神影天初 提問者

while底下不是try嗎?倒數(shù)第七不是catch嗎?
2018-08-12 回復(fù) 有任何疑惑可以回復(fù)我~
#2

omoide 回復(fù) 神影天初 提問者

因?yàn)槟愕膖ry catch內(nèi)并沒有什么語法錯(cuò)誤,所以他應(yīng)該不會(huì)檢測(cè)到,你不信可以去掉試試,還有也不必flag = false,因?yàn)榕cbreak重復(fù)了。
2018-08-18 回復(fù) 有任何疑惑可以回復(fù)我~
#3

神影天初 提問者 回復(fù) omoide

去掉try-catch會(huì)報(bào)錯(cuò)的,而且我的break是為了終止for循環(huán)而不是while循環(huán),你看清楚在回復(fù)。。。。。。
2018-08-20 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

實(shí)現(xiàn)代碼如下

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

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

幫助反饋 APP下載

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

公眾號(hào)

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