Java Reference
In-Depth Information
In this fragment, if i has the value 1, 2, or 3, the first println( ) statement executes. If it
is 4, the second println( ) statement executes. The “stacking” of case s, as shown in this
example, is common when several case s share common code.
Nested switch Statements
It is possible to have a switch as part of the statement sequence of an outer switch . This
is called a nested switch . Even if the case constants of the inner and outer switch contain
common values, no conflicts will arise. For example, the following code fragment is per-
fectly acceptable:
Try This 3-1 Start Building a Java Help System
This project builds a simple help system that displays the syntax for the Java control state-
ments. The program displays a menu containing the control statements and then waits for
you to choose one. After one is chosen, the syntax of the statement is displayed. In this first
version of the program, help is available for only the if and switch statements. The other
control statements are added in subsequent projects.
1. Create a file called Help.java .
2. The program begins by displaying the following menu:
 
Search WWH ::




Custom Search