O'Reilly logo

Java, A Beginner’s Guide, 5th Edition by Herbert Schildt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Try This 3-2 Improve the Java Help System

Help2.java

This project expands on the Java help system that was created in Try This 3-1. This version adds the syntax for the for, while, and do- while loops. It also checks the user’s menu selection, looping until a valid response is entered.

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

2. Change the first part of main( ) so that it uses a loop to display the choices, as shown here:

Image

Notice that a nested do- while loop is used to discard any unwanted characters remaining in the input buffer. After making this change, the program will loop, displaying the menu until the user enters a response that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required