Java Control Statements MCQ - Multiple Choice Questions And Answers
Q. What is the syntax for an if statement in Java?
A. if (condition) { // code block }B. if(condition) // code block
C. if [condition] { // code block }
D. if { // code block }
Q. Which keyword is used to exit a for loop in Java?
A. breakB. exit
C. continue
D. return
Q. Which of the following is NOT a control statement in Java?
A. if-elseB. switch-case
C. for-loop
D. do-while
Q. What is the purpose of the switch statement in Java?
A. To compare two valuesB. To iterate over a collection
C. To execute different blocks of code based on different values
D. To perform arithmetic operations
Q. How many conditions can be tested using a single if statement in Java?
A. 0B. 1
C. 2
D. Unlimited
Q. What is the purpose of the continue statement in Java?
A. To skip the current iteration of a loop and continue with the next iterationB. To terminate a loop and exit the current code block
C. To check a condition and execute different code blocks
D. To execute a block of code repeatedly
Q. What is the syntax for a while loop in Java?
A. while (condition) { // code block }B. while (condition) // code block
C. while [condition] { // code block }
D. while { // code block }
Q. What is the purpose of the default case in a switch statement in Java?
A. To compare two valuesB. To iterate over a collection
C. To execute a block of code when no other cases match the tested value
D. To perform arithmetic operations
Q. What is the purpose of the Predicate functional interface in Java 8?
A. To produce resultsB. To consume values
C. To filter elements based on a condition
D. To transform values
Q. Which keyword is used to exit a do-while loop in Java?
A. breakB. exit
C. continue
D. return
Q. Which of the following code snippets demonstrates the correct usage of a for loop in Java?
A.for (int i = 0; i < 10; i++) { System.out.println(i); }B.
for (int i = 1; i <= 10; i++) { System.out.println(i); }C.
for (int i = 10; i > 0; i--) { System.out.println(i); }D.
for (int i = 1; i < 10; i+=2) { System.out.println(i); }