ITPub博客

首页 > IT职业 > IT职场 > 简单的图书租借系统 两种方式租书

简单的图书租借系统 两种方式租书

IT职场 作者:ma_ti 时间:2021-09-09 08:57:21 0 删除 编辑
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);

    }

}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/93/viewspace-2807445/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2026-01-07

  • 博文量
    0
  • 访问量
    5411