Page 173 - CA_Blue( J )_Class10
P. 173
Which of the following is a type of above loop?
a. Finite loop b. Infinite loop
c. Null loop d. Empty loop
9. Consider the following code:
for(i=1;i<=10;i=i+2);
How many times the preceding loop will execute?
a. 10 times b. 1 time
c. 2 times d. 5 times
10. Consider the following code:
int i, s = 0;
i = 2;
do
{
s = s * i;
i = i + 2;
} while(i <= 4);
Which of the following is the final value of the s after executing the preceding code?
a. 8 b. 4
c. 0 d. 1
11. How many times will the following loop execute?
int i = 2;
while (i < 9)
{ i+=3;}
a. 0 b. 1
c. 2 d. 3
12. What is the purpose of the "continue" statement in a loop?
a. It exits the loop and continues with the next statement after the loop.
b. It skips the rest of the loop body and jumps to the next iteration.
c. It stops the loop and returns a value.
d. It initializes the loop variable.
13. What is the output of the following Java code?
int sum = 0;
for (int i = 1; i <= 5; i++)
{sum += i;}
System.out.println(sum);
a. 10 b. 15
c. 20 d. 25
14. What is the output of the following Java code?
for (int i = 0; i < 5; i++)
{
System.out.print(i + "-");
}
a. 0-1-2-3-4 b. 1-2-3-4-5
c. 0-1-2-3-4-5 d. 1-2-3-4
Answers
1. a 2. d 3. b 4. b 5. a 6. d 7. c 8. b 9. d 10. c
11. d 12. b 13.b 14.a
B. Fill in the blanks.
1. Consider the following code:
int a=0,b=4;
while(b<10)
{
a = ++b-b*2;
171
Iterative constructs in Java 171

