package 异常练习;
import java.util.Scanner;
public class Book {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] books={"论语","高数","语文"};
Scanner input=new Scanner(System.in);
try{
System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
int num=input.nextInt();
if(num==1){
System.out.println("输入图书名称:");
String bookname=input.next();
for(int i=0;i<books.length;i++){
if(bookname.equals(books[i])){
System.out.println("book:"+bookname);
break;
}else{if(i==books.length-1){
System.out.println("图书不存在!");
}}
}
}
if(num==2){
System.out.println("输入图书序号:");
int num2=input.nextInt();
if(num2>books.length){
System.out.println("图书不存在!");
}else{System.out.println("book:"+books [num2-1]);}
}
}catch(Exception e){
System.out.println("命令输入错误,请按提示输入数字命令!");
}
}
}