Java knowledge-process control-switch () {}

One of process control

switch (variable or expression) {

  case 1: **********break;

 

       case 2: **********

       case 3: **********

       ......

       default :  ***********

                  }

 

 

 

The type of switch can judge is very limited:

1: It is byte, short, char, int. In fact, byte short char will be forced to be converted to int type when used, so only int.

2: enum enumeration (not yet learned).

3: string (JDK1.7 or later)

The value after the case must be written in a literal value (that is, write down what the value is), or a constant (for example: Byte.MAX_VALUE is 127). It cannot be a variable.

 If there is no break, it will be penetrated to the end (default will also be penetrated).

When it encounters a break, it will return to the calling position and proceed down.

Guess you like

Origin www.cnblogs.com/raphaelJava-4560/p/12710345.html