I am a beginner in java. The task is to enter a books name and age recommendation. When pressing enter the program should no longer take input. The program just takes input for one book. Why is this the case?
Scanner scanner = new Scanner(System.in);
ArrayList<Book> bookList = new ArrayList();
while(true){
System.out.print("Input the name of the book, empty stops: "); //Only one input possible
String line = scanner.nextLine();
if(line.equals("")){
break;
}
System.out.print("Input the age recommendation: ");
int line2 = scanner.nextInt();
Book book = new Book(line, line2);
bookList.add(book);
}