import java.util.*;
public class CheckBook{
public static final String[] book = {"春天日记","高等数学","计算机概述","网络设计","论语","青春的躁动","大学英语"};
public static boolean right = true;
Scanner scanner = new Scanner(System.in);
public static void main(String[] args){
CheckBook checkBook = new CheckBook();
while(right){
try{
checkBook.test1();
}catch(Exce e){
e.printStackTrace();
}
}
}
public void test1()throws Exce {
System.out.println("请输入您要查询的id:");
if(scanner.hasNextInt()){
int number = scanner.nextInt();
if(number>book.length || number<0){
throw new Exce("序号不存在!");
}else{
System.out.println("请输入书籍名称:");
String bookName = scanner.next();
if(bookName.equals(book[number-1])){
System.out.println("图书馆中有此书,书的序号为:"+number);
right = false;
}else{
throw new Exce("图书不存在!");
}
}
}else{
throw new Exce ("错误命令异常!");
}
}
}
相关分类