Question
A. Code a while loop that will only let the user exit if the correct secret word is entered. The error message, INVALID secret word!
A. Code a while loop that will only let the user exit if the correct secret word is entered. The error message, INVALID secret word! Try again!, prints every time the loop is entered. If the user enters the correct secret word and before exiting the loop, a congratulatory message prints, Congratulations! Youve figured out the secret word!. The real secret word as a string literal is Bazinga and the variable to store the word entered by the user is secretWord. Assume the input variable for the Scanner class is already declared. HINT: This is a sentinel-controlled loop. Use the equals method from the String class. You should negate the result of the equals method.
B. A boolean variable called check is initialized to true. Code a while loop that keeps executing when door has a value other than 1, 2, or 3. The error message Invalid door number! Try again! prints when the value is not in the proper range; otherwise, Youve entered a correct door number. prints. Assume the input variable for the Scanner class and the door variable are already declared. Use single-selection if statements. HINT: Prompt for the door value at the beginning of the loop.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started