The format of the switch statement is as follows: (its function is to select a piece of code execution)
Copy Code code as follows:
Switch (integer selection factor) {
Case Integer value 1: statement; Break
Case Integer value 2: statement; Break
Case Integer value 3: statement; Break
Case Integer value 4: statement; Break
Case Integer value 5: statement; Break
...
Default: statement;
}
However, the following points should be noted:
The argument type of case in 1.switch can only be of type int, but Byte,short,char type is also possible because Byte,short,shar can be automatically promoted (automatic type conversion) to int, so the final one is the int type. Here's how Java has 8 data types: Byte, short, char, int, long, float, double, and a Boolean in which a Boolean cannot convert to any type of data, and a small type can be automatically converted to a large data type. Large data types are converted to small and must be made stronger.
2.case can be an expression.
3.break is used to jump out of the entire switch statement, and if not, the next branch will be executed.
4. Good programmers make good use of default.