I have to do a project for my Computer Science class. The problem is:
Patrons of a library can borrow up to three books. A patron, therefore, has a name and up to three
nextLine eats the newline character. nextInt leaves it in the input buffer, and the next readLine terminates immediately.
Quick fix: use readLine for everything, then parse the int from string read.
You just have to go to the next line. input.nextLine();
You can use nextInt();
to cause the the input to stop and wait for a response.
You use nextInt()
on line 71 of your code, which gets the integer answer the user provides. Then you use nextLine()
which Advances this scanner past the current line and returns the input that was skipped.. The input that is skipped is only the newline character from the previous nextInt()
call (It doesn't read the whole line only the int).
You can skip this by calling input.nextLine()
once before you want the input, or by using nextLine()
instead of nextInt()
and converting the string to the integer value.