Syntax java in a switch statement

/ *
About switch statement:
switch syntax structure
switch (int or string type literal or variable) {
literal or variable case int or string type:
Java statement:
Java statement:
Java statement:
...
BREAK;
case int or string type literals or variable:
Java statement:
Java statement:
Java statement:
...
BREAK;
literal or variable or string case int type:
Java statement:
Java statement:
Java statement:
...
BREAK;
...
default:
Java statement;
...
}

The implementation of the principle of 1.switch statement:
behind the switch parentheses among the "data" and the back of the case "data" one by one match,
successfully matched branch execution.
2. how match?
Sequentially from top to bottom in order to match
successful matching branch execution, a branch of which has "break", switch end
3.switch behind the rear case and can only be a literal or variable or string type int
course byte, short, char also and it is written directly to switch back case, because they can be converted automatically type
byte, short, char automatically converted bit int

4.case may be combined:
int = 10 A;
Switch (A) {
Case. 1: Case 2: CAES. 3: Case 10:
System.out.println ( "test code");
}

Released four original articles · won praise 0 · Views 59

Guess you like

Origin blog.csdn.net/qq_42895153/article/details/103937058