package com.condition.label;
/**
* @author Administrator
* 条件选择break和switch结合使用
*/
public class ConditionChoose {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 3; //switch操作的值必须为整数byte、int、char、short
switch(i)
{
case 1 :
System.out.println("The step is : 1"); //条件不满足
case 2 :
System.out.println("The step is : 2"); //条件不满足
case 3 :
System.out.println("The step is : 3"); //条件满足进入
case 4 :
System.out.println("The step is : 4"); //条件不满足,但仍会进入,因为上步满足进入后没有break,因为会继续执行下面的,直到遇到break、return或者结束
break;
default :
System.out.println("The step is : end...");
}
}
}
输出如下:
The step is : 3
The step is : 4