Switch can only compare numeric or character or class objects
First look at the parentheses of switch, and place the variable you want to take out the value. When the value is removed, the program begins to compare it to the number or character set in the case.
Executes the statement if it is met, and leaves the switch block until a break is encountered, and if there are no values or characters that match, the default statement is executed.
Default does not need to be, and if there are no actions to be handled by default, you can omit this part
Examples are as follows:
@Testpublic void Switchcase () {this.net (2);} private void net (int network) {switch (network) {Case 1: {System.out.println ("BAIDU"); Case 2:case 3: {System.out.println ("Baidupeview"); 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 cases in switch case and sees that execution is all clear.