What is the output for the below code?
public class Test{
public static void main(String[] args){
int i = 010;
int j = 07;
System.out.println(i);
System.out.println(j);
}
}
public class Test{
public static void main(String[] args){
int i = 010;
int j = 07;
System.out.println(i);
System.out.println(j);
}
}A. 8 7
B. 10 7
C. Compilation fails with an error at line 3
D. Compilation fails with an error at line 5
E. None of these
Answer: Option A
Solution (By Examveda Team)
By placing a zero in front of the number is an integer in octal form. 010 is in octal form so its value is 8
Join The Discussion
Comments (4)
Related Questions on Data Types and Variables
Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var

Priyank sharma: output will be 8
010 means
10 = 001 000
Right to left (001 000)
2³= 8
in code written plrintln which means 7 must be print in next line it print in same line
What is the O/P of following program:
public class DemoOctal {
public static void main(String[] args) {
int i=010;
System.out.println(i);
}
}