Vidyalelo
Java Programming · all questions

Flow Control
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

58

Questions

1/3

Page

Pick an option on a question to see the right answer and solution.

What is the purpose of the "if" statement in Java?

Select an option to see the answer and solution.

Which of the following is not a valid comparison operator in Java?

Select an option to see the answer and solution.

What is the output of the following code snippet?

int x = 5;
if (x > 3) {
System.out.println("Hello");
}

Select an option to see the answer and solution.

In Java, which statement is used to exit a loop prematurely?

Select an option to see the answer and solution.

What is the purpose of the "switch" statement in Java?

Select an option to see the answer and solution.

What is the default case in a "switch" statement used for?

Select an option to see the answer and solution.

In Java, which loop is suitable when you want to execute a block of code a specific number of times?

Select an option to see the answer and solution.

What is the result of the following code snippet?

int i = 1;
while (i <= 5) {
System.out.print(i + " ");
i++;
}

Select an option to see the answer and solution.

Which of the following is true about the "do-while" loop in Java?

Select an option to see the answer and solution.

In Java, what does the "continue" statement do?

Select an option to see the answer and solution.

What is the output of the following code snippet?

int j = 0;
while (j < 5) {
System.out.print(j + " ");
j += 2;
}

Select an option to see the answer and solution.

In Java, what does the "break" statement do in a loop?

Select an option to see the answer and solution.

What is the purpose of the "for-each" loop in Java?

Select an option to see the answer and solution.

In Java, what does the "default" keyword refer to in a "switch" statement?

Select an option to see the answer and solution.

What is the result of the following code snippet?

int k = 10;
do {
System.out.print(k + " ");
k -= 2;
} while (k > 0);

Select an option to see the answer and solution.

In Java, which loop is used when you want to execute a block of code as long as a condition is true?

Select an option to see the answer and solution.

What is the output of the following code snippet?

for (int m = 0; m < 5; m++) {
if (m == 2) {
continue;
}
System.out.print(m + " ");
}

Select an option to see the answer and solution.

In Java, what does the "switch" statement evaluate to determine which case to execute?

Select an option to see the answer and solution.

What is the purpose of the "if-else" statement in Java?

Select an option to see the answer and solution.

Which of the following is a valid way to create an infinite loop in Java?

Select an option to see the answer and solution.