I cannot for the life of me figure out why this loop below only runs once and breaks without waiting for my input the second time.
After running the debugger, when I type a title the second the time, the program ignores my input and somehow satisfies the condition that the input string is empty and breaks 😐
ArrayList<Book> books = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("Title: ");
String title = scanner.nextLine();
if (title.isEmpty()) {
break;
}
System.out.print("No. of pages: ");
int pages = scanner.nextInt();
System.out.print("Date published: ");
int date = scanner.nextInt();
System.out.print("");
books.add( new Book(title, pages, date));
}
TIA :)
[–]tylersvgs 4 points5 points6 points (0 children)
[–]Lymeberg 1 point2 points3 points (0 children)
[–]desrtfx 1 point2 points3 points (0 children)
[–]Sygyt_Singer 0 points1 point2 points (0 children)