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

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

百思不得其解,當(dāng)圖書名稱輸入錯(cuò)誤時(shí)不能重新執(zhí)行bookName()方法


package?librarySystem;
import?java.util.*;
public?class?LibrarySystem?{
????//自定義NoBookException異常類
????public?static?class?NoBookException?extends?Exception{
????????public?NoBookException(){}
????????public?NoBookException(String?message){
????????????super(message);
????????}
????}
????public?static?String[]?books={"高數(shù)","線代","幾何","生物","編程"};

????public?static?void?main(String[]?args)?{

????????System.out.println("序號(hào).\t書名");
????????for?(int?i=1;i<=5;i++){
????????????System.out.println(i+".\t\t"+books[i-1]);
????????}
????????LibrarySystem?lib=new?LibrarySystem();
????????lib.test();
????}

????public?void?test(){
????????try?{
????????????System.out.println("請(qǐng)選擇:1-按照序號(hào)查找圖書;2-按照名稱查找圖書");
????????????int?i?=?input();
????????????switch?(i)?{
????????????????case?1:
????????????????????bookNum();
????????????????????break;
????????????????case?2:
????????????????????bookName();
????????????????????break;
????????????????case?-1:
????????????????????test();
????????????????????break;
????????????????default:
????????????????????throw?new?NoBookException("請(qǐng)輸入1或2:");
????????????}
????????}
????????catch(NoBookException?e){
????????????System.out.println(e.getMessage());
????????????test();
????????}
????}

????public?void?bookNum(){
????????????System.out.println("請(qǐng)輸入圖書序號(hào):");
????????????try?{
????????????????int?i?=?input();
????????????????if?(i?>?0?&?i?<=?books.length)
????????????????????System.out.println(books[i-1]);
????????????????else
????????????????????throw?new?NoBookException("請(qǐng)輸入正確的序號(hào)");
????????????}catch(NoBookException?e){
????????????????System.out.println(e.getMessage());
????????????????bookNum();
????????????}
????}

????public?void?bookName(){
????????Scanner?sc?=?new?Scanner(System.in);
????????try?{
????????????System.out.println("請(qǐng)輸入書名:");
????????????String?book=?sc.next();
????????????boolean?flag=false;
????????????for?(String?i:books)?{
????????????????if?(book.equals(i))?{
????????????????????flag=true;
????????????????????System.out.println(i);
????????????????????break;
????????????????}
????????????}
????????????if(flag=false)?{
????????????????throw?new?NoBookException("請(qǐng)輸入正確的書名:");
????????????}
????????}catch?(NoBookException?e){
????????????System.out.println(e.getMessage());
????????????bookName();
????????}catch?(Exception?e){
????????????e.printStackTrace();
????????????bookName();
????????}
????}

????public?int?input(){
????????Scanner?sc?=?new?Scanner(System.in);
????????try?{
????????????int?i?=?sc.nextInt();
????????????return?i;
????????}catch?(Exception?e){
????????????System.out.println("請(qǐng)輸入整數(shù)");
????????????sc=new?Scanner(System.in);
????????????return?-1;
????????}
????}
}

第61行,當(dāng)圖書名稱輸入錯(cuò)誤時(shí)不能重新執(zhí)行bookName()方法,不知道哪出問題了

正在回答

2 回答

我想問你寫了多長(zhǎng)時(shí)間實(shí)現(xiàn)的

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

哈哈 弄明白了,問題出來第74行,flag==false!

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

舉報(bào)

0/150
提交
取消

百思不得其解,當(dāng)圖書名稱輸入錯(cuò)誤時(shí)不能重新執(zhí)行bookName()方法

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

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

幫助反饋 APP下載

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

公眾號(hào)

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