继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Java入门第三季1-9模拟借书系统

慕斯卡5202314
关注TA
已关注
手记 1
粉丝 0
获赞 39

package demo01book;
import java.util.Scanner;
public class Initail {
public static void main(String[] args) {
inputCommand();
}
public static void inputCommand(){

System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
Scanner sc = new Scanner(System.in);
try{
int flag = sc.nextInt();
if(flag == 1){inputName();
}
if(flag == 2){
inputNum();
}    
if(flag>2){
System.out.println("命令输入错误!请根据提示重新输入命令!");
inputCommand();
}
}catch(Exception e){    
System.out.println("命令输入错误!请根据提示重新输入命令!");
inputCommand();    
}
}

public static void inputName(){
String[] Books = {"Math","英语","化学"};
System.out.println("输入图书名称:");
Scanner sc = new Scanner(System.in,"GBK");
try{
String name = sc.next();
System.out.println("book:"+name);
inputCommand();     
for(int i=0;i<Books.length;i++){
if (Books[i].equals(name)){
    System.out.println("book:"+name);   
}
}
}catch(Exception e){
System.out.println("图书不存在!");
inputCommand();
}
}

public static void inputNum(){    
String[] Books = {"高数","英语","化学"};
System.out.println("输入图书序号:");
Scanner sc = new Scanner(System.in);
try{
int num = sc.nextInt();
System.out.println("book:"+Books[num]);
inputCommand();    
}catch(Exception e){
System.out.println("图书不存在!");
inputCommand();
}
}

}
打开App,阅读手记
4人推荐
发表评论
随时随地看视频慕课网APP