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 }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM