手记

java第三季——借书系统

package com.exception;

import java.util.Scanner;

public class Library {
static String[] books = {"C语言","高数","数据结构"};

public static void main(String[] args) throws Exception{

    try{
        System.out.println("请输入1:用书名查找书籍,2:用序号查找书籍");
        Scanner input = new Scanner(System.in);
        int choose = input.nextInt();
    if(choose == 1){
        System.out.println("请输入用书名");
        String na = input.next();
        try{
        for(int i=0;i<books.length;i++){
            if(na.equals(books[i])){
                System.out.println("book:"+na.toString());
            }
            break;
        }}catch(Exception e){
            e.printStackTrace();
        }
    }else if(choose ==2){
        System.out.println("请输入序号");
        int num = input.nextInt();
        for(int i=0;i<books.length;i++){
            if(num==i){
                System.out.println("book:"+books[i].toString());
            }
        }
    }
    }catch(Exception e){
        System.out.println("请输入正确命令");
    }

}

}

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