gpt4 book ai didi

Java错误: Input automatically go to next line without input yet

转载 作者:行者123 更新时间:2023-11-29 11:42:44 25 4
gpt4 key购买 nike

我有一个 bug (截屏)与我的程序。我想输入书名,但程序自动接受“无”,然后转到下一行。请在这里查看我的代码:

System.out.println("Book Management System");
System.out.println("1. Add book");
System.out.println("2. Delete book");
System.out.println("3. Update book information");
System.out.print("Enter your choice: ");
choice = input.nextInt();

switch (choice)
{
case 1:
System.out.println("Add a new book");
System.out.print("Enter title: ");
book_title = input.nextLine();
System.out.print("Enter author: ");
book_author = input.nextLine();
System.out.print("Enter publisher: ");
book_publisher = input.nextLine();
addBook(connection, preparedStatement, book_title, book_author, book_publisher);
break;

等等...这是我的 addBook 方法

 public static void addBook(Connection connection, PreparedStatement preparedStatement, String name, String author, String publisher) throws SQLException{
preparedStatement = connection.prepareStatement("INSERT INTO books.book_info (book_title, book_author, book_publisher) VALUES (?,?,?)");
preparedStatement.setString(1, name);
preparedStatement.setString(2, author);
preparedStatement.setString(3, publisher);
preparedStatement.executeUpdate();
System.out.println("Book added!");
}

这是全部code

最佳答案

关于Java错误: Input automatically go to next line without input yet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35495663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com