import java.util.Scanner;
import java.util.Arrays;
public class Tushuguan {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("欢迎使用图书管理系统!");
String []names={"语文","数学","英语","物理","化学"};//图书名称数组
int f=1;
do {
System.out.println("输入命令:");
System.out.println("按照名称查询图书请输入1;");
System.out.println("按照序号查询图书请输入2");
int num=input.nextInt();//输入命令序号
try{
if(num!=1&&num!=2){
throw new Exception();
}
}catch(Exception e){
System.out.println("请输入正确的命令!");
}
if(num==1){
System.out.println("请输入图书名称:");
String name=input.next();
try{
for(int i=0;i<names.length;i++){
if(name.equals(names[i])){
System.out.println(names[i]);
}else{
throw new Exception();
}}
}catch(Exception e){
System.out.println("您查找的图书不存在!");
continue;
}
}
try{
if(num==2){
System.out.println("请输入图书序号:");
Arrays.sort(names);
int nameNum=input.nextInt();
if(nameNum<5){
System.out.println(names[nameNum]);
}else{
throw new Exception();
}
}
}catch(Exception e){
System.out.println("您查找的图书不存在!");
continue;
}
}while(f==1);
input.close();
}
}