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.
Copy Help.java into a new file called Help2.java
Change the first part of main( ) so that it uses a loop when displaying the options.
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.
Note that there is no default statement present in this switch version. Since the menu loop ensures that a valid answer is entered, it is no longer necessary to include a default statement for handling a choice
invalid.
The above is the detailed content of Try this: Improve the Java help system. For more information, please follow other related articles on the PHP Chinese website!