+ 1
Awkward Output
public class Main { public static void main(String[] args) { int[] x = {120, 200, 016,016}; for(int i = 0; i < x.length; i++){ System.out.print(x[i] + " "); } } }
4 Answers
+ 6
I guess you mean the output of 016.
In Java numbers with leading zeros are octal numbers.
https://www.tutorialspoint.com/define-integer-literals-as-octal-values-in-java#:~:text=Literals%20with%20a%20leading%20zero,binary%20can%20use%200%2D1.
+ 4
016 => number proceeded or starts with 0 means its an octal number value, in number systems. You will get, Its equalent int in decimal is 14.
+ 2
I think the colleagues before explained it pretty well. Consider these prefixes:
0b - binary (e.g. 0b011001)
0x - hexadecimal ( e.g. 0xFF )
0 - octal ( e.g. your 016)
Zero mean that the following â16â is written in octal system. So itâs 6*8^0+1*8^1=8+6=14 in decimal.
+ 1
Output is : 120 200 14 14
i didn't get it, can anyone please explain how ?