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后边的代码回全部执行,一个不满足就会执行全部;

 

posted @ 2015-12-23 18:48  戒。  阅读(69)  评论(0编辑  收藏  举报