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

模拟借书系统

qq_孤影_2
关注TA
已关注
手记 1
粉丝 0
获赞 0

import java.util.Scanner;

public class TEST {

public static void main(String[] args) {
                    String[] str={"语文","数学","外语","政治","历史","地理","体育","音乐","物理","化学"};
        Scanner san=new Scanner(System.in);
        System.out.println("********欢迎进入图书查询系统********");
        System.out.println("1、按图书名查找   2、按图书序号查找");
        try {
            int score=san.nextInt();
            if(score==1){
                try {
                    System.out.println("请输入书名:");
                    String score1=san.next();
                    for(int i=0;i<str.length;i++){
                        if(str[i].contains(score1)){
                            System.out.println("Book"+str[i]);
                            san.close();
                            return;
                        }
                    }
                    System.out.println("图书名为【"+score1+"】的图书不存在!");
                    main(str);
                } catch (Exception e) {
                    System.out.println("书名输入错误!");
                    main(str);
                }
            }else if(score==2){
                try {
                    System.out.println("请输入序号(数字):");
                    int score1=san.nextInt();
                    if(score1>str.length-1){
                         System.out.println("序号为"+score1+"的图书不存在!");
                         main(str);
                    }else{
                        for(int i=0;i<str.length;i++){
                            if(score1==i){
                                System.out.println("Book"+str[i]);
                                san.close();
                                return;
                            }
                        }
                    }
                } catch (Exception e) {
                    System.out.println("序号输入错误!");
                    main(str);
                }
            }else if(score!=1||score!=2){
                System.out.println("请按提示输入!");
                main(str);
            }
        } catch (Exception e) {
            System.out.println("请按提示输入!");
            main(str);
        }
}

}

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