package rentbook;
import java.util.Scanner;
public class text {
public static Scanner scan=new Scanner(System.in);
public static book[] bo={
new book("高数"),
new book("物理"),
new book("语文"),
new book("英语"),
new book("c语言")
};
public static void main(String[] args) {
// TODO Auto-generated method stub
while (true ){
System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
int inputnum=inputnum1();
switch(inputnum){
case 1 : System.out.println("按照名称查找图书");
inputname();
break;
case 2: System.out.println("按照序号查找图书");
System.out.println("请输入序号");
try{
int putnum=inputnum1();
System.out.println(bo[putnum-1]);
}catch(Exception e){
scan=new Scanner(System.in);
System.out.println("您输入的数字过大");
}
break;
case -1 : System.out.println("请输入数字");break;
default: System.out.println("输入的数字不存在");continue;
}
}
}
private static void inputname() {
// TODO Auto-generated method stub
System.out.println("请输入书名");
String input=scan.nextLine();
try{
for(int i=0;i<bo.length;i++){
if(input.equals(bo[i].name))
System.out.println(bo[i].name);
}
}catch(Exception e){
scan=new Scanner(System.in);
System.out.println("请输入正确的书名");
}
}
private static int inputnum1() {
// TODO Auto-generated method stub
int a=scan.nextInt();
try{
return a;
}catch(Exception e){
scan=new Scanner(System.in);
return -1;
}
}
}
慕粉3291149
慕粉3291149
不存在的记忆
相关分类