A good answer might be:
Enter an integer: 1492 OK Enter an integer: Fourteen ninety two WRONG Enter an integer: 14.92 WRONG Enter an integer: -1492 OK Enter an integer: 1 4 9 2 WRONG |
NumberFormatException
If the user enters one of the WRONG lines,
the statement
This exception was passed out of the running program to the Java system, which stopped the program and wrote the error message.Enter an integer: 14.92 java.lang.NumberFormatException: 14.92 The parseInt method is just one method of the wrapper class Integer. It should be used like this: The stringVariable should contain only characters that can be interpreted as an integer.intVariable = Integer.parseInt( stringVariable ); |
QUESTION 17:Could the following be interpreted as an integer? Notice that there are two spaces preceeding the '8' character. Click Here after you have answered the question" 84" |