大佬们帮我看看是哪里出错了呀

来源:1-9 经验总结

weixin_慕用1239336

2023-01-12 13:36

borrowBookjava.util.ScannerBorrowBook {
    (String[] args) {
        String[] bookList =String[]bookList[]=bookList[]=bookList[]=bookList[]=System..println()order=Scanner scanner=Scanner(System.){
            order=scanner.nextInt()}(Exception e){
            System..println()}
        (order){
            :
                System..println()String bookNamebookName=scanner.next(){
                    (i=i<= bookList.i++)String book=bookList.get(i)(bookName.equals(book)){
                        System..println(+book)}
                }(Exception e){
                    System..println()}
                :
                System..println()num={
                    num=scanner.nextInt()}(Exception e){
                    System..println()}
                {
                    System..println(+bookList.get(num-))}(Exception e){
                    System..println()}
                :
                System..println()}
    }
}


写回答 关注

1回答

  • 零化域的缺失之环_cHSV59
    2025-03-08 11:55:59

    import java.util.Scanner; public class BorrowBook {    public static void main(String[] args) {        // 初始化图书列表        String[] bookList = {"Book1", "Book2", "Book3"};        Scanner scanner = new Scanner(System.in);        int order = 0;        try {            System.out.println("请输入操作序号:");            order = scanner.nextInt();        } catch (Exception e) {            System.out.println("输入有误:" + e.getMessage());        }        switch (order) {            case 1:                System.out.println("请输入要借阅的图书名称:");                String bookName = scanner.next();                try {                    for (int i = 0; i < bookList.length; i++) {                        String book = bookList[i];                        if (bookName.equals(book)) {                            System.out.println("借阅成功:" + book);                        }                    }                } catch (Exception e) {                    System.out.println("出现异常:" + e.getMessage());                }                break;            case 2:                System.out.println("请输入要借阅的图书序号:");                int num = 0;                try {                    num = scanner.nextInt();                } catch (Exception e) {                    System.out.println("输入有误:" + e.getMessage());                }                try {                    System.out.println("借阅成功:" + bookList[num - 1]);                } catch (Exception e) {                    System.out.println("出现异常:" + e.getMessage());                }                break;            default:                System.out.println("无效的操作序号");                break;        }        scanner.close();    } }

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409772 学习 · 4341 问题

查看课程

相似问题