How many times, at minimum, does the body of a do-while loop run?
The condition is checked after the body.
Control Flow Statements · Exercise 1 of 4
Twenty multiple-choice questions on Java control flow: if-else, classic switch and fall-through, switch expressions and yield, pattern matching switch, while, do-while, for, break, continue and labels. Pick an option to check your answer instantly.
How many times, at minimum, does the body of a do-while loop run?
The condition is checked after the body.
Can the body of a while loop run zero times?
while is a pre-test loop; so is for.
In a classic switch, what happens when a case has no break?
Arrow-style cases (->) do not fall through.
Which selector type is not allowed in a classic switch with constant case labels?
long, float, double and boolean are not allowed for value cases.
What is yield used for?
case X -> { …; yield value; }.
When can a switch expression over an enum omit default?
The same applies to a sealed type whose permitted subtypes are all covered.
Which is valid switch-expression syntax for "Saturday or Sunday"?
Labels are separated by commas.
In Java 21, what does case Integer i when i > 100 -> mean?
A guard adds a boolean condition to a pattern.
What happens when the selector of a classic switch (s) on a String is null?
Java 21 switches can add case null to handle it.
Which can be used as a classic case label?
Duplicate case values are compile errors.
Timed online tests with instant scores and explanations.