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 statement would be used to declare a 10-element integer array c?

a. array c = int[10]; b. c = int[10]; c. int array c[10]; d. int c[10];

Computer Science & Information Technology

The more ____________________ you have about a business contact, the better you can provide personalized service.

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

Computer Science & Information Technology