What is output by the following code? Discuss the output for grade values of 'A', 'B', 'C', 'D', 'F' and an invalid grade.

```
1 switch ( grade )
2 {
3 case 'A':
4 displayJLabel.setText( "Excellent!" );
5
6 case 'B':
7 displayJLabel.setText( "Very good!" );
8
9 case 'C':
10 displayJLabel.setText( "Good." );
11
12 case 'D':
13 displayJLabel.setText( "Poor." );
14
15 case 'F':
16 displayJLabel.setText( "Failure." );
17
18 default:
19 displayJLabel.setText( "Invalid grade." );
20 }
```


Regardless of the grade value, the result of the preceding code is that "Invalid grade" is displayed on displayJLabel. None of the cases has a break statement. So, when a match occurs, the statement in the body of that case executes, then program control con- tinues with the statement in the next case. This continues until the default case’s statement executes and the end of the switch statement is reached.

Computer Science & Information Technology

You might also like to view...

Which of the following icons, displayed as a result of typing in the Search box in Windows 8, links to the Control Panel options?

A.
B.
C.
D.

Computer Science & Information Technology

Revisit the Internet architecture as introduced in Chapter 3. What impact does the introduction of overlay networks have on this architecture, and in particular on the programmer’s conceptual view of the Internet?

What will be an ideal response?

Computer Science & Information Technology

The site name, which is the ____________________ that contains the site contents, can contain spaces.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

The Layer Two Tunneling Protocol uses what set of standards to provide encryption and security for a tunnel?

A. Point-to-Point Protocol (PPP) B. Microsoft Point-to-Point Encryption (MPPE) C. IP Security (IPSec) D. Advanced Encryption Standard (AES)

Computer Science & Information Technology