标签:break pre switch public static rgs int efault linux
package myproject; public class Switch_Case { public static void main(String[] args) { double d=Math.random(); int e=(int)(d*5); System.out.println(e); /* switch(e) { case 6: System.out.println("best"); //遇到break才终止运行;一般在每个case后面都要加break;以防穿透 break; case 5: System.out.println("better"); break; case 4: System.out.println("good"); break; default: System.out.println("bad"); } */ /* //利用穿透 switch(e) { case 0: case 2: case 4: System.out.println("偶数"); break; case 1: case 3: case 5: System.out.println("奇数"); break; default: System.out.println("奇数"); } */ String a="java"; switch(a){ //可以是字符串 case "java": System.out.println("java"); break; case "python": System.out.println("python"); break; default: System.out.println("linux"); } } }
标签:break pre switch public static rgs int efault linux
原文地址:https://www.cnblogs.com/hapyygril/p/12341004.html