"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Try this: Improve the Java help system

Try this: Improve the Java help system

Published on 2024-07-31
Browse:641

This version adds the syntax of for, while and do-while loops. It also checks the user's selection in the menu, looping until a response
valid to be entered.

  1. Copy Help.java into a new file called Help2.java

  2. Change the first part of main( ) so that it uses a loop when displaying the options.

Image description

Note that a nested do-while loop is used to discard any unwanted characters remaining in the input buffer. After this change, the program will enter a loop, displaying the menu until the user enters an answer between 1 and 5.

  1. Expand the switch statement to include for, while, and do-while loops, as shown below:

Image description

Note that there is no default statement present in this switch version. Since the menu loop ensures that a valid response is entered, it is no longer necessary to include a default statement for handling a choice
invalid.

Release Statement This article is reproduced at: https://dev.to/devsjavagirls/tente-isso-3-2-melhore-o-sistema-de-ajuda-java-3l04?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3