To make use of the strings produced by
readLine
, you first need to exploit several methods found in the
String
class:
trim
method produces a string with no spaces or other
whitespace characters on the ends. For example, if
line = " 4 7 3 "
, then:
line.trim() --> "4 7 3"
indexOf
method finds the position of its ordinary
argument in its target argument. If line = "4 7 3"
, then:
line.indexOf(" ") --> 1
substring
method, with one indexing argument, extracts a
string from its target argument, starting at the index.
line.substring(2) --> "7 3"
substring
method, with two indexing arguments, extracts a
string from its target argument.
line".substring(0, 1) --> "4"