package tryCatch;
import java.util.Scanner;
public class LiberaryTest {
private static final String[] Book ={"1:线性代数","2:高数","3:java","4:论语"};
public static void main(String[] args) {
System.out.println("欢迎来到图书馆,请查询你所要的图书");
LiberaryTest lt = new LiberaryTest();
lt.test();
}
public void test(){
System.out.println("输入命令:1-按序号查询 2-按书名查询");
try{
Scanner input = new Scanner(System.in);
int result = input.nextInt();
switch(result){
case 1:
Num();
break;
case 2:
Name();
break;
default:
System.out.println("你的输入有错!");
}
}catch(Exception e){
e.printStackTrace();
System.out.println("请输入正确数字选择类别查询");
}
test();
}
public void Num(){
System.out.println("请输入你想检索的序号:");
try{
Scanner input2 = new Scanner(System.in);
int result2 = input2.nextInt();
if(result2>Book.lengthresult2<1){
System.out.println("图书不存在");
}else{
System.out.println("你的书:"+Book[result2-1]);
}
}catch(Exception e){
e.printStackTrace();
System.out.println("请输入数字");
}
test();
}
public void Name(){
System.out.println("请输入你想检索的书名:");
try{
Scanner input3 = new Scanner(System.in);
String result3 = input3.next();
switch(result3){
case "线性代数":
System.out.println("你的图书:"+Book[0]);
break;
case "高数":
System.out.println("你的图书:"+Book[1]);
break;
case "java":
System.out.println("你的图书:"+Book[2]);
break;
case "论语":
System.out.println("你的图书:"+Book[3]);
break;
default:
System.out.println("图书不存在");
}
}catch(Exception e){
e.printStackTrace();
System.out.println("你的输入有误");
}
test();
}
}
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦