import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TestBook {
static ArrayList<String> as=new ArrayList<String>();
public static void main(String[] args) {
// TODO Auto-generated method stub
as.add("线性代数");
as.add("高等数学");
TestBook s=new TestBook();
s.method3();
}
void method3(){
System.out.println("***输入命令:1-按照名称查找图书;2-按照序号查找图书");
TestBook s=new TestBook();
s.method1();
s.method2();
}
void method2(){
Scanner in=new Scanner(System.in);
try {
int a=in.nextInt();
try{
System.out.println(a+"."+as.get(a));
}catch(IndexOutOfBoundsException s){
System.out.println("没有这本图书!");
method3();
}
}
catch(InputMismatchException s){
String a=in.next();
if(as.contains(a)){
System.out.println(as.indexOf(a)+a);
}
else{
System.out.println("没有这本图书!");
method3();
}
}
}
void method1(){
Scanner in=new Scanner(System.in);
try{
int a=in.nextInt();
if(a==2){
System.out.println("请输入图书序号:");
}
else if(a==1){
System.out.println("请输入图书名称:");
}
else{
System.out.println("输入有误,请重新输入!");
method1();
}
}
catch(InputMismatchException s){
System.out.println("输入有误,请重新输入!");
method1();
}
}
}