1Z0-811 • Practice Test 36
Free 1Z0-811 practice test — 15 questions with explanations. Set 36. No signup required.
A developer implements a menu-driven application using a switch statement inside a do-while loop. The menu options are 1-4, and option 4 is supposed to exit the application. However, after selecting option 4, the menu is displayed again before the application exits. The code is structured as follows: do { displayMenu(); choice = scanner.nextInt(); switch(choice) { case 1: // process option 1 break; case 2: // process option 2 break; case 3: // process option 3 break; case 4: break; // intended to exit loop
}
} while(choice != 4);The developer realizes that the break inside the switch only exits the switch, not the loop. What is the correct fix?