The string is not a exit command and is an acceptable integer, so the square root is printed.
123 does not match the RE
*[Qq](uit)?.*
so exitProgram()
returns false.
123 does match the RE *[0-9]+ *
The leading and trailing spaces from the user input are matched by the
beginning and end of the RE.
In the RE, there is a space in front of each *.
The 123 part of the input is matched by [0-9]+
The method goodNumber()
returns true, so
the spaces (if any) are trimmed off the string, and Integer.parseInt()
converts the characters into an int
which is then
converted to a double
and used with the square root method.
Could regular expressions be used to check user input from GUI interfaces?