Need Explanation of this Code :
public static void main(String[] args) {
int a=010;
int b=07;
System.out.println(a);
System.out.println(b);
}
OutPut :
8
7
Need Explanation of this Code :
public static void main(String[] args) {
int a=010;
int b=07;
System.out.println(a);
System.out.println(b);
}
OutPut :
8
7
An int prepended with 0
in Java represents an Octal, which means you count to 7, then represent the (decimal) value of 8 as 10, and continue form there.
As an example / for comparison:
Decimal Octal
8 10
9 11
10 12
11 13
16 20
17 21
24 30
25 31
64 100
65 101
etc...