Given the following sample:
public class Main { public static void main(String[] args) { System.out.println(1234); System.out.println(01234); } }
The Output is:
1234 668
Why?
This is because integer literals with a leading zero are octal integers (base 8):
1 * 8^3 + 2 * 8^2 + 3 * 8 + 4 = 668
2.1m questions
2.1m answers
60 comments
57.0k users