Integer Type Ranges
Easyjava
Print the smallest and largest value that each of byte, short and int can hold, using Java's built-in constants.
Input: none.
Output: three lines:
byte <min> <max>
short <min> <max>
int <min> <max>Example 1
Input
(none)
Output
byte -128 127 short -32768 32767 int -2147483648 2147483647
- Use Byte.MIN_VALUE / Byte.MAX_VALUE and the matching Short and Integer constants.
Hint 1
Byte.MIN_VALUE and Byte.MAX_VALUE give -128 and 127.
Hint 2
Concatenate the label, the min and the max with spaces.
Each primitive integer type has a fixed size and therefore a fixed range. The wrapper classes expose those limits as MINVALUE / MAXVALUE constants, so you never have to memorise the numbers.