switch语句中 case穿透的用法

 1 //反向利用case穿透
 2 public class TestSwitch {
 3     public static void main(String[] args){
 4         char c = 'a';
 5         int rand =(int) (26*Math.random());
 6         char c2 = (char)(c+rand);
 7         System.out.println(c2 + ":");
 8         switch (c2) {//如果是a e i o u 当中的一个会一直向下运行直到碰到break;
 9         case 'a':
10         case 'e':
11         case 'i':
12         case 'o':
13         case 'u':
14             System.out.println("元音");
15             break;
16         case 'y':
17         case 'w':
18             System.out.println("半元音");
19             break;
20 
21         default:
22             System.out.println("辅音");
23         }
24     }
25 }

posted @ 2018-02-05 22:38  zbgghost  阅读(2553)  评论(0)    收藏  举报