Find the error in the code segments, and explain how to correct it:
```
switch (n) {
case 1:
System.out.println("The number is 1");
case 2:
System.out.println("The number is 2");
break;
default:
System.out.println("The number is not 1 or 2");
break;
}
```
Error: The missing code is the break statement in the statements for the first case.
Correction: Add a break statement at the end of the statements for the first case. This omission is not necessarily an error if you want the statement of case 2: to ex- ecute every time the case 1: statement executes.
You might also like to view...
Google's ________ search operator searches the web for the definition of a specified word
Fill in the blank(s) with correct word
Communication that takes place through a telephoneis an example of simplex transmission.
Answer the following statement true (T) or false (F)