switch
【switch】:
switch()括号中的可以是byte,short,int,char.不能是double,float,long等.
例如:long a=1;
switch(a){...}他会说long到int会损失精度。
同时,case 后边只能是常量,而却跟switch()括号中的类型一样。
**案例**
int a=4;
switch(a){
defalut:System.out.println("default");
case 1:System.out.println("one"); break;
case 2: System.out.println("two");
case 3:System.out.println("three");}
结果是 default
one
如果int a=2;则结果是:
two
three
自己总结的地方:在没有break的条件下,如果满足其中一个,则case后边的代码回全部执行,一个不满足就会执行全部;
现在的几乎什么都不懂,但是不代表以后的我也是这样。