Page 185 - CA_Blue( J )_Class10
P. 185
3. Which of the following is a null loop?
a. while(i < 5) { } b. for(i = 0; i <= 10; i ++);
c. Both a and b d. do {int i;}while(i=10)
4. Consider the following code:
int a=5, b=2;
if(a>b)
{
a=a+1;
b=b*2;
}
System.out.print(a+ ":" +b);
Which of the following will be the output of the above code?
a. 6:2 b. 6:3
c. 6:4 d. 6:1
5. How many times the following loop will execute?
int i = 2, j = 10;
while(i < j) {
i = i / j;
System.out.println(i);
}
a. 0 b. 1
c. 5 d. infinite
6. This is an example of an iterative construct in Java?
a. if-else statement b. while loop
c. switch statement d. try-catch block
7. Which of the following is true about a "do-while" loop in Java?
a. The loop is executed at least once, regardless of the condition.
b. The loop may not execute at all if the condition is false initially.
c. The condition is evaluated before the loop body is executed.
d. It is functionally identical to a "for" loop.
8. What is the output of the following Java code?
for (int i = 0; i < 5; i++)
{
if (i == 3) {
continue;
}
System.out.print(i + " ");
}
a. 0 1 2 3 4 b. 0 1 2 3
c. 0 1 2 4 d. 0 1 2
9. Which loop is called exit control loop?
a. for loop b. while loop
c. do while loop d. infinite loop
10. What will be the output of the following code?
int i = 1;
while (i <= 10) {
if (i % 5 == 0) {
break;
}
System.out.print(i + " ");
i+=2;
}
a. 1 2 3 4 5 6 7 8 9 10 b. 1 2 3 4 5
c. 1 3 5 7 9 d. 1 3
183
Iterative constructs in Java 183

