最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機立即綁定

弄了3小時,終于搞定了。。。。。。


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-按書名查找 2-按編號查找");? ??

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){//按書名查找######

int v=0;//暫用

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

? ? 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("此書不存在!!");

? ? throw new Exception();

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

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

int bookNum;

System.out.println("請輸入編號:");

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

bookNum=input.nextInt();

}catch(Exception e) {

System.out.println("請輸入正確編號?。?從1開始)");

throw new Exception();

}

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

throw new Exception();

}else {

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

}

//至此按編號查找實現(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("歡迎進入圖書館查書系統(tǒng)\n請輸入您的指令:\n1-按名稱查找圖書\n2-按編號查找圖書\n");
??Scanner in = new Scanner(System.in);
??int i = in.nextInt();
??
??try {
???if (i == 1) {
????System.out.println("請輸入您需要查找的圖書的書名");
????name();
???} else if (i == 2) {
????System.out.println("請輸入您需要查找的圖書的編號");
????number();
???} else {
????throw new Exception();
???}
??} catch (Exception e) {
???System.out.println("請輸入正確指令\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("編號: " + BOOK[index][0] + "? 書名 " + BOOK[index][1] + " 存在");
???} else {
????throw new Exception();
???}
??} catch (Exception e) {
???System.out.println("該書不存在,請重新輸入正確書名......");
???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("編號: " + BOOK[index][0] + "? 書名 " + BOOK[index][1] + " 存在");
???} else {
????throw new Exception();
???}
??} catch (Exception e) {
???System.out.println("該書不存在,請重新輸入正確編號......");
???number();
??}
?}
?
?public static String[][] BOOK = {{"0001","語文"},{"0002","數(shù)學(xué)"},{"0003","英語"},{"0004","體育"}};
}

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

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

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

感同身受_

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

舉報

0/150
提交
取消

弄了3小時,終于搞定了。。。。。。

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

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

幫助反饋 APP下載

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

公眾號

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