I would use a Scanner object based on System.in
to read the line in, using if (myScanner.hasNextLine())
and myScanner.nextLine()
method pairs.
Then the line would need to be parsed, and here I'd offer you two possible ways:
- Consider using a new Scanner based on the line just read in, say into a String variable called
line
, a "line Scanner" so to speak,Scanner lineScanner = new Scanner(line)
, and get your tokens vialineScanner.next()
,lineScanner.nextInt()
,lineScanner.next()
, andlineScanner.nextInt()
, in that order. Don't forget toclose()
the lineScanner when done using it. - Or use
String#split(" ")
to split the String into an array of the four subStrings that were separated by the space.
Then in the for loop where you parse the line, create any object needed based on the data obtained.