Number Parsing
Integer user
input |
Enter an integer:-34 You entered -34 Enter an integer:five Sorry, but 'five' is not an integer. |
No. 176
Why using String userInput =
null?
|
Q: |
The former listing initializes the
So the dummy assignment |
|
A: |
Actually the Java™ compiler is not
clever enough analyzing the Thus the possibility of an uninitialized
|
Value: 13 |
Exception in thread "main" java.lang.NumberFormatException: For input string: "201" ... at de.hdm_stuttgart.sd1... |
No. 177
Parsing short values
|
Q: |
Which outcome do you expect? Try to answer without prior execution. Explain the result. |
|
A: |
Value:32767
Exception in thread "main" java.lang.NumberFormatException:
Value out of range. Value:"32768" Radix:10 at
java.lang.Short.parseShort(Short.java:120)
at java.lang.Short.parseShort(Short.java:144)
at de.hdm_stuttgart.sd1.ParseShortTooBig.main(ParseShortTooBig.java:8) |
No. 178
Parsing short values in hexadecimal
representation
|
Q: |
An image processing application yields the following type of data: We are looking for a class method parsing these hex values
and converting them to The provided sample data may then be processed like: Result: C9: 201 AF3: 2803 B: 11 TipHave a look to the binary parse example and think about representations. |
|
A: |
Hexadecimal representation uses a radix value of 16 to be
passed to |
|
A: |
Value:32767
Exception in thread "main" java.lang.NumberFormatException:
Value out of range. Value:"32768" Radix:10 at
java.lang.Short.parseShort(Short.java:120)
at java.lang.Short.parseShort(Short.java:144)
at de.hdm_stuttgart.sd1.ParseShortTooBig.main(ParseShortTooBig.java:8) |
