package myproject;
/**
*
* @author 李瑞琦
* 一般情况下if用来范围性的判断
* 如果指定具体的值则用switch case
* switch以等值的方式匹配case对应的值,如果符合要求则执行紧跟在case后边的语句
* 直到执行到break为止,如果没有break则一直执行到程序的末尾。
*
*/
public class TestSwitch {
public static void main(String[] args){
//车辆限号问题
int number = (int)(Math.random()*7+1);
switch(number){
case 1:
System.out.println("今天限号为1 9");
break;
case 2:
System.out.println("今天限号为2 8");
break;
case 3:
System.out.println("今天限号为3 7");
break;
case 4:
System.out.println("今天限号为4 6");
break;
case 5:
System.out.println("今天限号为5 0");
break;
default:
System.out.println("今天不限号");
break;
}
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交