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

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

輸入正確書(shū)名后還會(huì)提示暫無(wú)此書(shū)

import?java.util.Scanner;
public?class?Book?{
?
?/**
??*?@param?args
??*/
?public?static?void?main(String[]?args)?{
??//?TODO?Auto-generated?method?stub
??Scanner?input=new?Scanner(System.in);
??System.out.println("歡迎來(lái)到書(shū)庫(kù)");
?//定義圖書(shū)數(shù)組
??final?int?[]?booknum?={1,2,3,4,5};
??final?String?[]?bookname={"c++","java","計(jì)算機(jī)基礎(chǔ)","匯編語(yǔ)言","算法"};
?//展示編號(hào)和圖書(shū)
??for(int?i=0;i<5;i++)
??System.out.println(booknum[i]+"\t"+bookname[i]+"\t");
?//選擇方式
??System.out.println("請(qǐng)輸入查詢(xún)方式的編號(hào)!1.按照編號(hào)查詢(xún)?2.按照書(shū)名查詢(xún)");
??try{
??String?number=input.next();
?//進(jìn)行選擇
??switch(number){
??case?"1":??//1編號(hào)查詢(xún)
???System.out.println("請(qǐng)輸入編號(hào)");
???nums(bookname);
???break;
??case?"2":??//2書(shū)名查詢(xún)
???System.out.println("請(qǐng)輸入書(shū)名");
???names(bookname);
???break;
??default:??//輸入錯(cuò)誤
???System.out.println("輸入錯(cuò)誤,請(qǐng)輸入正確數(shù)字");
??}
??}catch(Exception?aaa){
???System.out.println(aaa.getMessage());
??}
??
}
?
?//編號(hào)查詢(xún)方法
?public?static?void?nums(String?[]?bookname){
??Scanner?in=new?Scanner(System.in);
??try{
???int?a=in.nextInt();
???System.out.println("給你"+bookname[a-1]);
??}catch(Exception?a){
???System.out.println("無(wú)此書(shū)");
??}
?}
?
?//名字查詢(xún)方法
?public?static?void?names(String?[]?bookname)
???throws?Exception{
??Scanner?in=new?Scanner(System.in);
???String?b=in.nextLine();
???for(int?i=0;i<bookname.length;i++){
????if?(b.equals(bookname[i]))
????System.out.println("給你"+bookname[i]);
???}throw?new?Exception("暫無(wú)此書(shū)");
?}?
?}


正在回答

1 回答

//?名字查詢(xún)方法
????public?static?void?names(String[]?bookname)?throws?Exception?{
????????Scanner?in?=?new?Scanner(System.in);
????????String?b?=?in.nextLine();
????????for?(int?i?=?0;?i?<?bookname.length;?i++)?{
????????????if?(b.equals(bookname[i]))?{
????????????????System.out.println("給你"?+?bookname[i]);
????????????????return;
????????????}
????????}
????????throw?new?Exception("暫無(wú)此書(shū)");
????}

改成這樣就行了,求采納!

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

慕沐7780984 提問(wèn)者

謝謝 但是這是為什么呢?
2017-02-09 回復(fù) 有任何疑惑可以回復(fù)我~
#2

ziom 回復(fù) 慕沐7780984 提問(wèn)者

代碼是順序執(zhí)行的,在循環(huán)里如果找到了對(duì)應(yīng)的書(shū)籍就應(yīng)該終止循環(huán),直接返回,否則最一行拋異常的語(yǔ)句就會(huì)執(zhí)行
2017-02-09 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕沐7780984 提問(wèn)者 回復(fù) ziom

ok 謝啦
2017-02-09 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

輸入正確書(shū)名后還會(huì)提示暫無(wú)此書(shū)

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

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

幫助反饋 APP下載

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

公眾號(hào)

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