Flow Control - Study Mode
[#51] 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?
Correct Answer
(C) int y = 11
Explanation
Solution: 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.
[#52] What will be the result? int i = 10
while(i++ <= 10){
i++
}
System.out.print(i)
Correct Answer
(D) 13
Explanation
Solution: Initially i=10, when it reaches to while statement i++ <= 10 here i = 10 so condition become ture. For next use i become 11 and i++ statment will excuted and i become 12. Then again its go to while loop and check i++ <=10 here i = 12 so condition becomes fail and i become 13. Therefore when print statement will execute after while loop it Print 13
[#53] What is the output of the following code snippet? int j = 0
while (j < 5) { System.out.print(j + " ")
j += 2
}
Correct Answer
(C) 0 2 4
[#54] What is the result of the following code snippet? int k = 10
do { System.out.print(k + " ")
k -= 2
} while (k > 0)
Correct Answer
(C) 10 8 6 4 2
[#55] What is the output of the following code snippet? for (int m = 0
m < 5
m++) { if (m == 2) { continue
} System.out.print(m + " ")
}
Correct Answer
(C) 0 1 3 4