-10

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

Kjartan
  • 18,591
  • 15
  • 71
  • 96
Abhishek
  • 3
  • 3

1 Answers1

2

An int prepended with 0in 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...
Kjartan
  • 18,591
  • 15
  • 71
  • 96