Java Reference
In-Depth Information
***********************************
| PAYROLL DATA PROCESSING |
| ROUTINE |
***********************************
| Options: |
| 1. enter new employee |
| 2. calculate payroll |
| 3. delete employee |
| 4. enter employee data |
***********************************
| Enter option number: |
***********************************
When using this menu, the user enters an integer value for selecting the
desired processing option in the payroll program. One way of implement-
ing a menu selection is to use several consecutive if statements to test the
value of the input variable. The Java switch construct provides an alterna-
tive mechanism for selecting among multiple options. The switch con-
sists of the following elements:
1. The switch keyword
2. Acontrollingexpressionenclosedinparentheses.Mustbeofintegertype.
3. One or more case statements followed by an integer or character constant,
or an expression that evaluates to a constant. Each case statement termi-
nates in a colon symbol.
4. An optional break statement at the end of each case block. When the break
is encountered, all other case statements are skipped.
5. An optional default statement. The default case receives control if none of
the other case statements have executed.
The switch construct provides a simple alternative to a complicated if,
else-if, and else chain. The general form of the switch statement is as fol-
lows:
switch (expression)
{
case value1:
statement;
statement;
...
[break;]
case value2:
statement;
statement;
...
[break;]
...
[default:]
statement;
Search WWH ::




Custom Search