Java Loops MCQs with answers Page - 2

You will find multiple-choice questions (MCQs) related to #Java Loops here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 828.43K Points
Coach

Q. Which keyword exits a loop immediately in Java?

  • (A) stop
  • (B) continue
  • (C) exit
  • (D) break

A

Admin • 828.43K Points
Coach

Q. How many times will this loop execute?
for(int i = 0; i < 5; i++) {
// code
}

  • (A) 4
  • (B) 5
  • (C) 6
  • (D) 0

A

Admin • 828.43K Points
Coach

Q. What is the output of the following code?
int i = 0;
while(i < 3) {
System.out.print(i);
i++;
}

  • (A) 0123
  • (B) 012
  • (C) 123
  • (D) 01

A

Admin • 828.43K Points
Coach

Q. What is true about nested loops in Java?

  • (A) Only while loops can be nested
  • (B) Loops cannot be nested
  • (C) Any loop can be nested inside another loop
  • (D) Only for loops can be nested

A

Admin • 828.43K Points
Coach

Q. What is the output of this code?
for(int i=1;i<=3;i++){
for(int j=1;j<=2;j++){
System.out.print("*");
}
}

  • (A) ****
  • (B) ******
  • (C) ***
  • (D) **

A

Admin • 828.43K Points
Coach

Q. Which loop type is most suitable for menu-driven programs where the menu must be shown at least once?

  • (A) for
  • (B) while
  • (C) do-while
  • (D) foreach

A

Admin • 828.43K Points
Coach

Q. What will be the output?
for(int i = 0; i < 10; i += 2) {
System.out.print(i + " ");
}

  • (A) 0 1 2 3 4 5 6 7 8 9
  • (B) 0 2 4 6 8
  • (C) 2 4 6 8 10
  • (D) 1 3 5 7 9

A

Admin • 828.43K Points
Coach

Q. What does the continue statement do in Java?

  • (A) Exits the program
  • (B) Skips the entire loop
  • (C) Skips current iteration and continues with next
  • (D) Throws an exception

A

Admin • 828.43K Points
Coach

Q. How many times will the loop run?
int i = 0;
while(i > 0) {
System.out.println(i);
}

  • (A) Infinite times
  • (B) 1 time
  • (C) 0 times
  • (D) Depends on JVM

A

Admin • 828.43K Points
Coach

Q. Which statement can be used to terminate both inner and outer loops?

  • (A) break
  • (B) continue
  • (C) return
  • (D) exit
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More