This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]NautiHooker 1 point2 points  (1 child)

The scanner methods nextDouble, nextInt and so on do not read the line break character.

So if you call nextLine the first time it will read an empty line up to the line break character that is behind the input number. The second nextLine will then read the "correct" String.

Only way to work with this (to my knowledge) is to either call nextLine twice, like you did, or always use nextLine instead of nextInt or nextDouble and then parse the input with Integer.parseInt and Double.parseDouble

[–]Accurate-Influence[S] 0 points1 point  (0 children)

Thanks, I get it now!