You need to call an additional in.nextLine() before calling in.nextLine() to read in a line. It must consume an additional new line symbol.
As an explanation, you can use this input as an example:
23[Enter] 43[Enter] Somestring[Enter]
(23 and 43 can be just any number, the important part is a new line )
You need to call in.nextLine() to use the new line from the previous in.nextInt() , especially the new line character after 43 in the above example.
nextInt() will consume as many digits as possible and stop when the next character is not a digit, so a new line appears. nextLine() will read everything until it encounters a new line. To do this, you will need an additional nextLine() to delete the new line after 43 , so you can continue reading Somestring on the next line.
If, for example, your input looks like this:
23 43 Somestring[Enter]
You do not press Enter and just keep typing, then your current code will show a line (which will be Somestring , notice a space), because after 43 there is no new line that prevents it.
source share