This switch statement should determine whether an int is even or odd. Find the error(s) in the following code:
```
1 switch ( value % 2 )
2 {
3 case 0:
4 outputJTextField.setText( "Even Integer" );
5
6 case 1:
7 outputJTextField.setText( "Odd Integer" );
8 break;
9
10 } // end switch
```
When the expression value % 2 evaluates to 0, the integer is even, so the first case executes. However, because there is no break statement in the first case, the statement at line 7 will also execute. So outputJTextField will always contain "Odd Integer" after the preceding switch statement executes.
You might also like to view...
PDF files are commonly used to share files for business because free readers are readily available
Indicate whether the statement is true or false
In virtualized computing, a single computer is capable of supporting a single operating system.
Answer the following statement true (T) or false (F)
Task patterns can involve ____ tasks.
A: dependent B: multiple successor C: multiple predecessor D: all of the above
The data type of the value in a case clause within a switch statement must be compatible with the data type of which of the following?
A. selectorExpression B. if statement C. else clause D. defaultExpression