java - Why int j = 012 giving output 10? -
in actual project happened accidentally here modified small program.
i can't figure out why giving output 10?
public class int { public static void main(string args[]) { int j=012;//accidentaly put 0 system.out.println(j);// prints 10?? } }
after put 2 zeros still giving output 10.
than change 012 0123 , giving output 83?
can explain why ?
than change 012 0123 , giving output 83?
because, it's taken octal base (8), since numeral have 0 in leading. so, it's corresponding decimal value 10
012 :
2 * 8 ^ 0 + 1 * 8 ^ 1 = 10
0123 :
3 * 8 ^ 0 + 2 * 8 ^ 1 + 1 * 8 ^ 3 = 83
Comments
Post a Comment