Why can’t I enter a string in Scanner(System.in), when calling nextLine()-method?

.nextInt() gets the next int, but doesn’t read the new line character. This means that when you ask it to read the “next line”, you read til the end of the new line character from the first time.

You can insert another .nextLine() after you get the int to fix this. Or (I prefer this way), read the int in as a string, and parse it to an int.

Leave a Comment