0
int a[] = {120, 50, 016};

for(int P : a)
    System.out.print(P+" ");

I expect the output of above code is 120 50 16, but the actual output is 120 50 14.

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
  • 4
    `016` is 14 in radix 8 – Eran Aug 15 '19 at 08:53
  • 2
    The leading 0 stands for octal numeral system: In this your 016 = 1 * (8^1) + 6 * (8^0) = 14 – tobsob Aug 15 '19 at 08:57
  • have a look at Java Language Specification [3.10. Literals](https://docs.oracle.com/javase/specs/jls/se12/html/jls-3.html#jls-3.10) - some more *strange* (good to know) facts, like underscore in literal numbers – user85421 Aug 15 '19 at 09:24

2 Answers2

0

That is because '016' is behaving as and its octal value 14.

0

It is octal base 8 because you have a 0 in front.

See the following link: https://en.wikipedia.org/wiki/Octal

A. van Hugten
  • 715
  • 5
  • 16