0
What is the output and why?
public class Program { public static void main(String[] args) { int i=010; int j = 07; System.out.println(i); System.out.println(j); } }
3 Answers
+ 2
The result is 8 and 7.
This is because 010 and 07 are octal representation of integers. In java any number preceded by an 0 is considered to be an octal number
+ 3
Gaurav Rawat , variable i is interpreted as octal number, because it starts with 0. When you convert 010 from octal to decimal the result is 8.
+ 2
Any integer preceded by 0 means it is an octal representation.
So decimal representation of 10 is
1Ă(8^1) + 0Ă(8^0)
8+0 = 8
Similarly solve for the other.