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

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

作業(yè)提交,大家給提提意見,有什么簡單點(diǎn)的方法實(shí)現(xiàn)嗎

package?com.imooc.exception;

import?java.util.Arrays;
import?java.util.Scanner;

public?class?BorrowBook?{
????public?static?void?main(String[]?args)?{
????????BorrowBook?borrowBook=new?BorrowBook();
???????borrowBook.Borrow();
????}

????public?void?Borrow(){
????????//?書號分別對應(yīng)的是1,2,3,4
????????String[]?books={"西游記","紅樓夢","三國演義","水滸傳"};
????????System.out.println("歡迎使用圖書管理系統(tǒng)!");
????????System.out.println("1.?按照書名查找圖書???????2.按照序號查找圖書");
????????Scanner?input?=new?Scanner(System.in);
????????try?{
???????????int?num=input.nextInt();
???????????if?(num==1){
???????????????System.out.println("請輸入書名:");
???????????????Scanner?input1=new?Scanner(System.in);
???????????????String?bookname=input1.nextLine();
???????????????boolean?book=?Arrays.asList(books).contains(bookname);
???????????????if?(book==true){
???????????????????System.out.println(bookname+"借書成功!");
???????????????}else?{
???????????????????throw?new?NoBookException("此書不存在");
???????????????}
???????????}
???????????if?(num==2){
???????????????System.out.println("請輸入書號:");
???????????????Scanner?input2=new?Scanner(System.in);
???????????????int?shuhao=input2.nextInt();

???????????????????if?(shuhao>0?&&?shuhao<=books.length?){
???????????????????????System.out.println(books[shuhao-1]+"借書成功!");
???????????????????}else{
???????????????????????throw?new?NoBookException("查無此書!");
???????????????????}
???????????}
????????}catch?(NoBookException?e){
????????????System.out.println(e);
????????????System.out.println();
????????????Borrow();
????????}
????}
}


正在回答

4 回答

你的shuhao應(yīng)該>=0,就比如36行,應(yīng)該這么寫:if?(shuhao>=0??&& shuhao<books.length?)。因?yàn)閿?shù)組下標(biāo)從0開始

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

這個(gè)序號是自動(dòng)就給定好了的嗎?

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

拆雞

他拿的是索引嗎????
2019-07-31 回復(fù) 有任何疑惑可以回復(fù)我~

package?com.imooc.exception;?import?java.util.Arrays;import?java.util.Scanner;?public?class?BorrowBook?{????public?static?void?main(String[]?args)?{????????BorrowBook?borrowBook=new?BorrowBook();???????borrowBook.Borrow();????}?????public?void?Borrow(){????????//?書號分別對應(yīng)的是1,2,3,4????????String[]?books={"西游記","紅樓夢","三國演義","水滸傳"};????????System.out.println("歡迎使用圖書管理系統(tǒng)!");????????System.out.println("1.?按照書名查找圖書???????2.按照序號查找圖書");????????Scanner?input?=new?Scanner(System.in);????????try?{???????????int?num=input.nextInt();???????????if?(num==1){???????????????System.out.println("請輸入書名:");???????????????Scanner?input1=new?Scanner(System.in);???????????????String?bookname=input1.nextLine();???????????????boolean?book=?Arrays.asList(books).contains(bookname);???????????????if?(book==true){???????????????????System.out.println(bookname+"借書成功!");???????????????}else?{???????????????????throw?new?NoBookException("此書不存在");???????????????}???????????}???????????if?(num==2){???????????????System.out.println("請輸入書號:");???????????????Scanner?input2=new?Scanner(System.in);???????????????int?shuhao=input2.nextInt();????????????????????if?(shuhao>0?&&?shuhao<=books.length?){???????????????????????System.out.println(books[shuhao-1]+"借書成功!");???????????????????}else{???????????????????????throw?new?NoBookException("查無此書!");???????????????????}???????????}????????}catch?(NoBookException?e){????????????System.out.println(e);????????????System.out.println();????????????Borrow();????????}????}}

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

你這個(gè)已經(jīng)挺簡單了,要是借書前加個(gè)循環(huán)輸出都有哪些書號+書名,就更好了

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

拆雞

大哥 你那邊這想法有完成嗎 我和你同樣的想法
2019-07-31 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

作業(yè)提交,大家給提提意見,有什么簡單點(diǎn)的方法實(shí)現(xiàn)嗎

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

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

幫助反饋 APP下載

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

公眾號

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