Page 218 - CA_Blue( J )_Class10
P. 218
System.out.println("Hello World");
}
}
Assertion (A): The following code will print "Hello World" exactly 5 times.
Reason (R): A "while" loop in Java checks the condition before executing the loop body.
3. for (int i = 1; i < 4; i++)
{
for (int j = 1; j <= 5; j++)
{
System.out.println("i: " + i + ", j: " + j);
}
}
Assertion (A): In the following nested loops, the innermost statement will execute a total of 20 times.
Reason (R): The outer loop runs 3 times, and for each iteration of the outer loop, the inner loop runs 5 times.
Ans. 1. a 2. c 3. d
Unsolved Questions
A. Tick ( ) the correct answer.
1. A cake has 3 layers, and each layer has 4 flavors. How many times will the inner loop execute in total?
for (int layer = 1; layer <= 3; layer++) {
for (int flavor = 1; flavor <= 4; flavor++) {
System.out.println("Layer " + layer + ", Flavor " + flavor);
}
}
a. 3 b. 4
c. 7 d. 12
2. What is the final value of total number of steps?
int layers = 4,stepsPerLayer = 5, totalSteps = 0;
for (int i = 1; i <= layers; i++) {
for (int j = 1; j <= stepsPerLayer; j++) {
totalSteps++;
}
}
System.out.println("Total baking steps: " + totalSteps);
a. 4 b. 5
c. 9 d. 20
3. What will be the output of the following nested for loop?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
a. *** b. *
*** **
*** ***
216216 Touchpad Computer Applications-X

