控制流程系列教材 (二)- java的switch语句
16lz
2021-04-19
控制流程系列教材 (二)- java的switch语句
更多内容,点击了解: https://how2j.cn/k/control-flow/control-flow-switch/272.html
步骤1:switch
示例 1 : switch
switch可以使用byte,short,int,char,String,enum
注: 每个表达式结束,都应该有一个break;
注: String在Java1.7之前是不支持的, Java从1.7开始支持switch用String的,编译后是把String转化为hash值,其实还是整数
注: enum是枚举类型,在枚举章节有详细讲解
public class HelloWorld {public static void main(String[] args) { //如果使用if elseint day = 5;if (day==1)System.out.println("星期一"); else if (day==2)System.out.println("星期二");else if (day==3)System.out.println("星期三");else if (day==4)System.out.println("星期四");else if (day==5)System.out.println("星期五");else if (day==6)System.out.println("星期六");else if (day==7)System.out.println("星期天");elseSystem.out.println("这个是什么鬼?"); //如果使用switchswitch(day){case 1:System.out.println("星期一");break;case 2:System.out.println("星期二");break;case 3:System.out.println("星期三");break;case 4:System.out.println("星期四");break;case 5:System.out.println("星期五");break;case 6:System.out.println("星期六");break;case 7:System.out.println("星期天");break;default:System.out.println("这个是什么鬼?");} }}
更多内容,点击了解: https://how2j.cn/k/control-flow/control-flow-switch/272.html
©著作权归作者所有:来自51CTO博客作者wx5c4afeea27343的原创作品,如需转载,请注明出处,否则将追究法律责任更多相关文章
- C语言进阶(六)--自定义类型详解(结构体+枚举+联合)
- 记一次用WPScan辅助***WordPress站点
- HTML中表格和表单的应用实例 (MD)
- HTML中表格和表单的应用实例
- 第二天作业(课程表)
- php学习日记——课程表
- 第二课 课程表与注册表单
- 使用表格写课程表代码
- 课程表和用户注册的作业