public class Test{
public static void main(String [] args){
int x = 0;
// insert code here
do{ } while(x++ < y);
System.out.println(x);
}
}
Which option, inserted at line 4, produces the output 12?
public class Test{
public static void main(String [] args){
int x = 0;
// insert code here
do{ } while(x++ < y);
System.out.println(x);
}
}
A. int y = x;
B. int y = 10;
C. int y = 11;
D. int y = 12;
E. None of the above will allow compilation to succeed.
Answer: Option C
Solution(By Examveda Team)
x reaches the value of 11, at which point the while test fails.
x is then incremented (after the comparison test!), and the println() method runs.
Hence, choice A, B, D, E, and F are incorrect based on the above point.
Related Questions on Flow Control
What is the purpose of the "if" statement in Java?
A. To execute a block of code conditionally
B. To create loops
C. To declare variables
D. To define methods
A. No output
B. Error
C. Hello
D. 5
Join The Discussion