Why is 09 "too large" of an integer number? [duplicate]
Solution 1:
Numbers beginning with 0
are considered octal – and 9 is not an octal digit (but (conventionally) 0-7 are).
Hexadecimal literals begin with 0x
, e.g. 0xA
.
Up until Java 6, there was no literal notation for binary and you'll had to use something like
int a = Integer.parseInt("1011011", 2);
where the second argument specifies the desired base.
Java 7 now has binary literals.
In Java SE 7, the integral types (byte, short, int, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix
0b
or0B
to the number.
Solution 2:
Integer literals beginning with a "0" are treated as octal. The permissible digits are 0 through 7.
Solution 3:
Integers beginning with the digit 0 are octal (base 8) numbers. The largest octal digit is 7; after 07 comes 010 (which is equal to decimal 8!)
012 (octal twelve) is 010 (octal ten, which is decimal 8) plus 2, or decimal 10.