Application / Output Based Questions for ICSE 10th Computer Applications
1. What does the following 'for' loop do?
for (int i = 0; i < 5; i++) {
System.out.print(i + " ");
}
a. Prints numbers from 1 to 5
b. Prints numbers from 0 to 4
c. Prints numbers from 1 to 4
d. Prints numbers from 0 to 5
2. Identify the type of loop used in the following code snippet:
while (true) {
System.out.println("Infinite Loop");
}
a. for loop
b. while loop
c. do-while loop
d. switch statement
3. What will be the output of the following 'do-while' loop?
int x = 5;
do {
System.out.print(x + " ");
x--;
} while (x > 0);
a. 5 4 3 2 1
b. 5 4 3 2
c. 4 3 2 1
d. 5 4 3
4. In the given code snippet, how many times will the 'while' loop execute?
int count = 0;
while (count < 3) {
count++;
}
a. 0 times
b. 1 time
c. 2 times
d. 3 times
5. What is the purpose of the 'break' statement in the following 'for' loop?
for (int i = 1; i <= 10; i++) {
if (i == 5) {
break;
}
System.out.print(i + " ");
}
a. Skips the iteration when i is 5
b. Terminates the loop when i is 5
c. Continues the loop when i is 5
d. Prints numbers from 1 to 5
6. Which of the following 'for' loop statements is incorrect?
a.
for (int i = 0; i <= 10; i++) {
System.out.print(i + " ");
}
b.
for (int i = 0; i < 10; i += 2) {
System.out.print(i + " ");
}
c.
for (int i = 10; i > 0; i--) {
System.out.print(i + " ");
}
d.
for (int i = 0; i < 10; i--) {
System.out.print(i + " ");
}
7. What does the 'continue' statement do in the following 'while' loop?
int x = 0;
while (x < 5) {
x++;
if (x % 2 == 0) {
continue;
}
System.out.print(x + " ");
}
a. Skips even values of x
b. Skips odd values of x
c. Terminates the loop
d. Prints all values of x
8. What is the output of the following 'nested for' loop?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
System.out.print(i * j + " ");
}
}
a. 1 2 2 4 3 6
b. 1 2 3 4 5 6
c. 2 4 6 8 10 12
d. 1 3 2 6 3 9
9. What will be the output of the 'for' loop below?
for (int i = 0; i < 4; i++) {
for (int j = 0; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
a.
*
* *
* * *
* * * *
b.
*
*
c.
* * * *
* * *
* *
*
d.
*
*
10. Which keyword is used for labeling a loop in Java?
a. label
b. loop
c. mark
d. identifier
11. What is the output of the following nested 'for' loop?
for (int i = 1; i <= 3; i++) {
for (int j = 3; j >= i; j--) {
System.out.print(j + " ");
}
System.out.println();
}
a. 3 2 1
b. 3 2 1 2 1 1
c. 3 3 3 2 2 1
d. 3 3 3 2 2 2
12. Identify the error in the following 'do-while' loop:
int x = 5;
do {
System.out.print(x + " ");
} while (x < 5);
a. The condition should be 'x > 5'
b. The loop body should be in curly braces
c. The loop will result in an infinite loop
d. There is no error
13. What does the following 'while' loop do?
int i = 0;
while (i < 10) {
i += 2;
}
a. Prints even numbers from 0 to 10
b. Prints odd numbers from 0 to 10
c. Prints numbers from 2 to 10
d. Results in an infinite loop
14. In the 'for' loop below, what happens if you remove the 'continue' statement?
for (int i = 0; i < 5; i++) {
if (i % 2 == 0) {
continue;
}
System.out.print(i + " ");
}
a. The loop will not compile
b. The loop will print even numbers
c. The loop will print odd numbers
d. The loop will print nothing
15. What is the significance of the 'label' in the following code snippet?
outer: for (int i = 0; i < 3; i++) {
inner: for (int j = 0; j < 2; j++) {
if (i == 1 && j == 1) {
break outer;
}
System.out.print(i * j + " ");
}
}
a. Skips the current iteration of the inner loop
b. Terminates the outer loop when i is 1 and j is 1
c. Labels the outer loop with 'outer' and inner loop with 'inner'
d. Continues to the next iteration of the outer loop
16. What will be the output of the following 'while' loop?
int x = 0;
while (x < 5) {
x++;
if (x % 2 != 0) {
continue;
}
System.out.print(x + " ");
}
a. 2 4
b. 2 4 6
c. 1 3 5
d. 1 2 3 4 5
Comments
Post a Comment