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
What is the maximum value that can be stored in a byte variable in Java?
A. 127
B. 255
C. 32767
D. 64
What is the default value of an int variable in Java if it's not explicitly initialized?
A. 0
B. 1
C. -1
D. Null
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);
}
}