Java examples for Language Basics:int
When an integer literal starts with a zero and has at least two digits, it is considered to be in the octal number format.
The following line of code assigns a decimal value of 17 (021 in octal) to num:
// 021 is in octal number format, not in decimal int num = 021;
The following two lines assign a value of 17 to the variable num1:
// No leading zero - decimal number format int num1 = 17; // Leading zero - octal number format. // 021 in octal is the same as 17 in decimal int num1 = 021;
An int literal in octal format must have at least two digits, and must start with a zero.
The number 0 is zero in decimal number format, and 00 is zero in octal number format.
// Assigns zero to num1, 0 is in the decimal number format int num1 = 0; // Assigns zero to num1, 00 is in the octal number format int num1 = 00;
0 and 00 represent the same value, zero.
All int literals in the hexadecimal number format start with 0x or 0X and they must contain at least one hexadecimal digit.