switch ( expression ) The data type of the value of the selected expression can only be a byte short int char
{
case takes value 1:
execute the statement;
break;
case takes value 2:
execute the statement;
break;
..... ...
Default:
execute the statement;
break;}
Switch statement features:
There are only four types of 1.switch statement choices:byte,short,int , Char .
2. alternative answers are not in order. But execution must be performed from the first case .
3. defaultis executed only if all of the case does not match .
4. End Feature: Encounters a break, or executes to the end of the curly brace.
Description
in theSwitch (An expression), the expression inside the Swith can only be aan integer expressionorEnumeration Constants(larger font), an integer expression can be an int primitive type or an integer wrapper type, because,Byte,short,char can be implicitly converted to int, so, these types as well as these types ofPackage Typeis also possible. Obviously, long and string types do not conform to the syntax of switch, and cannot be implicitly converted to int types, so they cannot be used in Swtich statements.
int x = 3; switch (x) { default: system.out.println ("no"); break; case 1: system.out.println ("C"); break; case 4: System.out.println ("a");  &Nbsp; break; case 2: system.out.println ("B"); break;} Break on the last side can be omitted.
Switch statements, and if very much like, in development, in the end who use it?
When deciding on a specific number of values, you can use ifor switch, which is recommended for use with switch.
If you can also judge the interval, you can also judge the result of the operation as a Boolean type.
So if the application is more.
Java Syntax Basics-Program Flow Control-Select structure-switch statements