一、if
if语句对条件表达式进行一次测试,若测试为真,则执行下面的语句,否则跳过该语句


二、if-else
当条件表达式为真时,执行语句块1,否则,执行语句块2。即else部分


三、if-else if-else
逐条if语句进行判断。条件匹配,进入语句体;否则对if语句继续匹配


四、switch多选择结构
Switch语句:case标签必须是整数(byte,short,char,int)或者枚举,不能是字符串(JDK7之前)
一般在每个case后面都要加break,防止出现case穿透现象
当然也可以反过来有效利用case的穿透现象,如例子所示


JDK7中的switch新特性:Switch语句case标签可以是字符串

网友评论