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

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

弄了3小時(shí),終于搞定了。。。。。。


package bookSystem;

import java.util.Scanner;

public class bookSelectSystem {


public static void main(String[] args) {

bookSelectSystem test = new bookSelectSystem();

test.Select();

}

//####################################################

public void Select() {

String[] bookName= {"JAVA","Python","C++"};

System.out.println("輸入命令:1-按書(shū)名查找 2-按編號(hào)查找");? ??

Scanner input=new Scanner(System.in);

try{//檢查輸入匹配


int input1=input.nextInt();

if(input1!=1 && input1!=2) {//再判斷

throw new Exception();//意外發(fā)現(xiàn)

}else if (input1 == 1){//按書(shū)名查找######

int v=0;//暫用

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

? ? String inputBookName = input.next();

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

? ? if(inputBookName.equals(bookName[i])) {//需要equals(待研究)

? ? System.out.println("Your book:"+bookName[i]);

? ? v=5;//暫用

? ? }

? ? }

? ? if(v==0) {

? ? System.out.println("此書(shū)不存在!!");

? ? throw new Exception();

? ? }//至此按書(shū)名查找成功實(shí)現(xiàn)!#############

}else if(input1==2) {//這里是按編號(hào)查找?。。。?!

int bookNum;

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

try{//判斷輸入是否匹配int

bookNum=input.nextInt();

}catch(Exception e) {

System.out.println("請(qǐng)輸入正確編號(hào)??!(從1開(kāi)始)");

throw new Exception();

}

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

throw new Exception();

}else {

System.out.println("Your book:"+bookName[bookNum-1]);

}

//至此按編號(hào)查找實(shí)現(xiàn)?。。。。。。。。?!

}

? ??

}catch(Exception e) {

System.out.println("——情根據(jù)提示輸入正確命令!——");

Select();

}

}


}



正在回答

2 回答

import java.util.Scanner;
public class Library {
?public static void main(String[] args) {
??Index();
?}
?
?public static void Index() {
??System.out.println("歡迎進(jìn)入圖書(shū)館查書(shū)系統(tǒng)\n請(qǐng)輸入您的指令:\n1-按名稱查找圖書(shū)\n2-按編號(hào)查找圖書(shū)\n");
??Scanner in = new Scanner(System.in);
??int i = in.nextInt();
??
??try {
???if (i == 1) {
????System.out.println("請(qǐng)輸入您需要查找的圖書(shū)的書(shū)名");
????name();
???} else if (i == 2) {
????System.out.println("請(qǐng)輸入您需要查找的圖書(shū)的編號(hào)");
????number();
???} else {
????throw new Exception();
???}
??} catch (Exception e) {
???System.out.println("請(qǐng)輸入正確指令\n");
???Index();
??}
?}
?
?public static void name() {
??Scanner in = new Scanner(System.in);
??String str = in.nextLine();
??int index = -1;
??try {
???for (int i = 0; i < BOOK.length; i++) {
????if (BOOK[i][1].equals(str)) {
?????index = i;
?????break;
????}
???}
???if (index != -1) {
????System.out.println("編號(hào): " + BOOK[index][0] + "? 書(shū)名 " + BOOK[index][1] + " 存在");
???} else {
????throw new Exception();
???}
??} catch (Exception e) {
???System.out.println("該書(shū)不存在,請(qǐng)重新輸入正確書(shū)名......");
???name();
??}
?}
?
?public static void number() {
??Scanner in = new Scanner(System.in);
??String str = in.nextLine();
??int index = -1;
??try {
???for (int i = 0; i < BOOK.length; i++) {
????if (BOOK[i][0].equals(str)) {
?????index = i;
?????break;
????}
???}
???if (index != -1) {
????System.out.println("編號(hào): " + BOOK[index][0] + "? 書(shū)名 " + BOOK[index][1] + " 存在");
???} else {
????throw new Exception();
???}
??} catch (Exception e) {
???System.out.println("該書(shū)不存在,請(qǐng)重新輸入正確編號(hào)......");
???number();
??}
?}
?
?public static String[][] BOOK = {{"0001","語(yǔ)文"},{"0002","數(shù)學(xué)"},{"0003","英語(yǔ)"},{"0004","體育"}};
}

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

為什么這個(gè)采納的代碼中,方法和數(shù)組都寫(xiě)成靜態(tài)的

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

感同身受_

這樣就可以直接調(diào)用吧,不用再實(shí)例化對(duì)象去調(diào)用
2019-02-13 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

弄了3小時(shí),終于搞定了。。。。。。

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