有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何使用java中的Scanner类在一个字符串变量中存储两个或多个单词,然后在另一个字符串变量中存储下一个输入?

Scanner sc = new Scanner(System.in);

    System.out.println("Enter title of the book: ");
    String title = sc.next();
    System.out.println("Enter the author: ");
    String author = sc.next();

    String bookID = bookID();

    Book b = new Book(author,title,bookID,true);
    books.add(b);


    System.out.println( title + " by "+ author +" added to library.");
    System.out.println("Book ID: " + bookID);

这将产生以下输出,标题为“乱世佳人”,作者为玛格丽特·米切尔:

Gone by with added to library
Book ID:456423156

有什么办法可以让我绕过这件事吗


共 (1) 个答案