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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!