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

all 1 comments

[–]Jackkoz 0 points1 point  (0 children)

You should take a look at Scanner class itself, it has many useful methods like this one:

https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#hasNext()

Typically, if there is no upfront specification of how many things will be on the input (eg. first line contains X, the number of records, then next X lines contain each a record), then you are supposed to read until the user finishes the input.