1

I could not understand the exact computation logic here. How is 01234 being treated.

public static void main(String[] args) {
    System.out.println(01234 + 43210);
    System.out.println(1234 + 43210);
}

Output

43878
44444
Mateusz Sroka
  • 2,255
  • 2
  • 17
  • 19
Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
  • 1
    possible duplicate of [09 is not recognized where as 9 is recognized](http://stackoverflow.com/questions/970039/09-is-not-recognized-where-as-9-is-recognized) – Hexaholic Apr 24 '15 at 09:58

2 Answers2

3

A number literal starting with a leading zero is treated as octal (base 8). So 01234 is in fact 668 (decimal)

Alex Salauyou
  • 14,185
  • 5
  • 45
  • 67
Michel Billaud
  • 1,758
  • 11
  • 14
1

How is 01234 being treated?

It is treated here as octal. Any number starting with 0 is octal.

Masudul
  • 21,823
  • 5
  • 43
  • 58