public class Test {
public static void main(String[] args) {
int i = 012;
System.out.println(i);
}
}
Why the output is : <
Octal Number :
Any number start with 0
is considered as an octal number (012
) i.e. base-8 number system
Simple octal number evaluation :
1*8^1 + 2*8^0 = 10
Octal Number
For More information about Number System
012 is the octal value for 10 in decimal. So your telling java to print the integer at octal pos 012. Here: http://www.asciitable.com/ shows octal to decimal vaulue conversions.
If a number starts with 0 it's an octal number with base 8. 012 is in decimal a 10
See the JLS:
An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 interspersed with underscores, and can represent a positive, zero, or negative integer.
It's a good practice to write:
int i = 0_12;
It might be clearer now, i
in decimal is 2*80 + 1*81 = 10.