JAVA中的switch-each语句

来源:互联网 发布:ubuntu samba 客户端 编辑:程序博客网 时间:2024/06/07 00:01
 Scanner in = new Scanner(System.in); int number = in.nextInt(); switch(number){ case 1:System.out.println("happy"); case 2:System.out.println("today"); case 3:System.out.println("is years");break; default:System.out.println("hahaha");


上图是语句,执行的时候会从number开始一直执行遇到break时,执行才会结束。

如果case里没有number的选项,则会选择执行default

0 0
原创粉丝点击