String response = input.next(); // Wrong
String response = input.nextLine(); // Right
When you do input.next()
, you just read the first word of the line.
When you afterwards do input.nextLine()
, you read up until the next line feed.
That means that if you type y<enter>
, the first statement will read y
and the second statement will read up until the <enter>
which is just the empty string.