Home > Java > javaTutorial > body text

Try this: Improve the Java help system

WBOY
Release: 2024-07-18 10:55:30
Original
254 people have browsed it

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 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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!