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();
switch(putnum){
case -1: System.out.println("请输入数字");break;
default:System.out.println(bo[putnum-1]+"已经被您选中了");break;
}
}catch(Exception e){
System.out.println("您输入的数字过大");
}
break;
case -1 : System.out.println("请输入数字");break;
default: System.out.println("输入的数字不存在");
}
}
}
private static void inputname() {
// TODO Auto-generated method stub
System.out.println("请输入书名");
String input=scan.next();
for(int i=0;i<bo.length;i++){
if(input.equals(bo[i].name))
System.out.println(bo[i].name+"已经被您选中了");
else if(i==bo.length-1){
System.out.println("请输入正确的书名");
break;
}
}
}
private static int inputnum1() {
// TODO Auto-generated method stub
try{
int a=scan.nextInt();
return a;
}catch(Exception e){
return -1;
}
}
}
sntatas
Caption_1210
相关分类