Last Updated: January 3, 2026
30 quizzes
Choose the correct method to check if an age allows entry when using an if statement condition.
boolean canEnter = age.(18);Click an option to fill the blank:
Complete the switch statement to handle all unmatched values with a default branch.
: System.out.println("Unknown option");Click an option to fill the blank:
Select the correct keyword to immediately exit a for loop when a match is found.
if (id == targetId) ;Click an option to fill the blank:
Which control flow construct is most appropriate for choosing one of many constant integer options such as menu selections 1-5?
You need to validate user age and apply different discounts for age <18, 18-64, and 65+. What structure best fits this?
Which loop is best when you must execute a block at least once, then repeat while a condition stays true?
You must process each element of an int[] without modifying the array or using indices. What is the most concise option?
In a while loop that reads user input until "quit" is entered, what is the main risk if you forget to update the input variable inside the loop?
In a nested for loop over rows and columns, which statement lets you skip only the rest of the current inner loop iteration when a cell is empty?
What happens if you omit break in a non-last case of a switch statement?
You want to exit both inner and outer loops when a value is found in a matrix. Which feature helps you target the outer loop directly?
Which loop construct automatically stops once it has visited each element in a List<String>?
Where can a label be applied in Java to use with break or continue?
Order the steps to read commands in a loop until the user types "exit" using a while loop.
Drag and drop to reorder, or use the arrows.
Order the steps to search a 2D array and stop both loops when a target is found using a labeled break.
Drag and drop to reorder, or use the arrows.
What is the output of this conditional discount logic?
1int price = 100;
2int age = 70;
3if (age >= 65) {
4 price -= 20;
5} else if (age >= 18) {
6 price -= 10;
7} else {
8 price -= 5;
9}
10System.out.println(price);What does this switch statement print for the given day code?
1int dayCode = 6;
2String type;
3switch (dayCode) {
4 case 1:
5 case 7:
6 type = "Weekend";
7 break;
8 case 2:
9 case 3:
10 case 4:
11 case 5:
12 case 6:
13 type = "Weekday";
14 break;
15 default:
16 type = "Invalid";
17}
18System.out.println(type);What is printed after this for loop with continue?
1int sum = 0;
2for (int i = 1; i <= 5; i++) {
3 if (i % 2 == 0) {
4 continue;
5 }
6 sum += i;
7}
8System.out.println(sum);Predict the output of this do-while loop that validates a counter.
1int count = 3;
2int printed = 0;
3do {
4 printed++;
5 count--;
6} while (count > 3);
7System.out.println(printed);What is the single line of output of the enhanced for loop with break?
1int[] values = {2, 4, 6, 8};
2int found = -1;
3for (int v : values) {
4 if (v > 5) {
5 found = v;
6 break;
7 }
8}
9System.out.println(found);Find the bug in this while loop that reads until "stop" is entered.
Click on the line(s) that contain the bug.
Scanner scanner = new Scanner(System.in);String cmd = scanner.nextLine();while (!cmd.equalsIgnoreCase("stop")) { System.out.println("Command: " + cmd);}scanner.close();Identify the bug in this enhanced for loop that tries to skip negative scores.
Click on the line(s) that contain the bug.
int[] scores = {10, -1, 20};for (int s : scores) { if (s < 0) break; System.out.println("Valid: " + s);}Match each control flow construct with its best description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each keyword with how it affects loop execution.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to iterate over an array of tasks and stop the loop when a "DONE" marker is found.
String[] tasks = {"START", "LOAD", "DONE", "SAVE"};for ( task : tasks) { if (.equals("DONE")) { ; } System.out.println(task);}Click an option to fill blank 1:
Fill in the blanks to repeatedly prompt for a PIN using a do-while loop until the correct value is entered.
int correctPin = 1234;int entered;do { entered = .nextInt();} while ( != correctPin);Click an option to fill blank 1:
Complete the while loop that sums positive numbers in an array using an index.
int[] nums = {3, -2, 5};int i = 0;int total = 0;while (i nums.length) { if (nums[i] < 0) { i++; ; } total += nums[i]; i++;}Click an option to fill blank 1:
Complete the switch statement that categorizes a status code, using a default branch for unknown values.
int status = 404;String message;switch (status) { case 200: message = "OK"; break; case 500: message = "Error"; break; : message = ;}System.out.println(message);Click an option to fill blank 1:
Click the line that causes only the inner loop to exit when a zero is found.
Click on the line to select.
int[][] grid = {{1, 2}, {3, 0}};outer: for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[i].length; j++) { if (grid[i][j] == 0) { break; } }}System.out.println("Done");Click the line where a labeled continue sends control to the next iteration of the outer loop.
Click on the line to select.
outer: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j > i) { continue outer; } }}System.out.println("Finished");