首页 > 其他 > 详细

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

时间:2020-02-27 19:33:00      阅读:71      评论:0      收藏:0      [点我收藏+]

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("辅音");
}

}
}技术分享图片

 

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

原文:https://www.cnblogs.com/CCTVCHCH/p/12373722.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!