Switch case and break in java
Switch can only compare values, characters, or class objects
First, let's look at the brackets of the switch, where the variable you want to take out the value. After a value is taken out, the program starts to compare it with the number or character set in case,
If yes, execute the statement until the switch block is left after the break is met. If no matching value or character exists, the default statement is executed,
Default is not required. If there is no action to be processed by default, you can save this part.
Example:
@ Testpublic void switchCase () {this.net (2);} private void net (int network) {switch (network) {case 1: {System. out. println ("BAIDU"); break;} case 2: case 3: {System. out. println ("BAIDUpeview"); break;} case 4: {break;} case 5: case 6: {break;} case 7: {break;} case 8: case 9: {break;} default: {System. out. println ("network [" + network + "is not match .... "); break ;}}}
This example lists all the situations of the switch case. It is clear that one execution is complete.