051_switch语句的使用 052_while循环详解 053_for循环详解_dowhile简介 054_嵌套循环_循环相关练习

051_switch语句的使用

package testmode2;
/**
* 测试switch语句
* 遇到多值判断的时候,使用switch。当然,switch完全可以使用ifelseifelse代替!
* @author
*
*/
public class TestSwitch {
public static void main(String[] args) {
int month = (int) (1 + 12 * Math.random());
System.out.println("月份:" + month);

switch (month) {
case 1:
System.out.println("一月份!过新年了!");
break;
case 2:
System.out.println("二月份!开春了");
break;
default:
System.out.println("我是其他月份!");
break;
}

System.out.println("##############");
char c = 'a';
int rand = (int) (26 * Math.random());
char c2 = (char) (c + rand);
System.out.print(c2 + ": ");

switch (c2) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("元音");
break;
case 'y':
case 'w':
System.out.println("半元音");
break;
default:
System.out.println("辅音");
}

}
}

猜你喜欢

转载自www.cnblogs.com/CCTVCHCH/p/12373722.html
今日推荐