手记

借书系统初级学习各位大神多指教

package jieshuxitong;

import java.util.Scanner;

public class jiashu {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("**********欢迎使用借书系统*************");
     Scanner input = new Scanner(System.in);
    while (true) {

        System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
        try {
            switch (input.next()) {
            case "1":
                System.out.println("请输入图书名称:");
                try {
                    String c = input.next();
                    switch (c) {
                    case "chinese":
                        System.out.println("book:chinese");
                        break ;
                    case "mathematical":
                        System.out.println("book:mathematical");
                        break;
                    case "english":
                        System.out.println("book:english");
                        break;
                    default:
                        System.out.println("没有" + c + "图书");
                        continue;
                    }

                } catch (Exception e) {
                    // TODO: handle exception
                    Exception as = new Exception("请输入字符串!");
                    as.initCause(e);
                    throw as;
                }
            break;
            case "2":
                System.out.println("请输入图书序号:");
                try {
                    String g = input.next();
                    switch (g) {
                    case "1":
                        System.out.println("book:chinese");
                        break;
                    case "2":
                        System.out.println("book:mathematical");
                        break;
                    case "3":
                        System.out.println("book:english");
                        break;
                    default:
                        System.out.println("没有" + g + "图书");
                        continue;
                    }

                } catch (Exception e) {
                    // TODO: handle exception
                    Exception as = new Exception("请输入整数!");
                    as.initCause(e);
                    throw as;
                }
            break;
            default :
                System.out.println("输入不正确!");
                break;
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("输错了哈哈哈");
        }
    }
}

}

2人推荐
随时随地看视频
慕课网APP

热门评论

哈哈哈 真的是初学啊  加油

查看全部评论