package com.imooc.bookrent;
import java.util.Scanner;
public class BookRent {
static String[] books=new String[80];
static int b=0;
public void test1(){
System.out.println("请选择查书方式:输入1.序号 输入2.书名");
do{
try {
Scanner sc=new Scanner(System.in);
int x=sc.nextInt();
if(x==1){
System.out.println("请输入图书序号:");
b=x;
break;
}else if(x==2){
System.out.println("请输入书名:");
b=x;
break;
}else{
System.out.println("请输入有效数字:");
continue;
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("输入有误!请重新输入:");
continue;
}
}while(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
BookRent bk=new BookRent();
bk.test1();
do{
Scanner sc=new Scanner(System.in);
try{
if(b==1){
int n=sc.nextInt();
System.out.println("租书:"+books[n]);
}
}catch(Exception e){
System.out.println("不存在该图书,请重新输入:");
continue;
}
if(b==2){
String n=sc.nextLine();
System.out.println("租书:"+n);
}
}while(true);
}
}
打开App,阅读手记