I语句流图 aIse 布尔表达式 true 语句(组) 下一条语句
If语句流图 布尔表达式 语句(组) 下一条语句 true false
322i£.else语句 语法为: if (booleanExpression) statement(s)-for-the-true-casei else statement(s)-for-the-false-casei
3.2.2 if...else 语句 语法为: if (booleanExpression) { statement(s)-for-the-true-case; } else { statement(s)-for-the-false-case; }
if.else example 如果半径大于0,则计算并显示圆的面积,否则提示无效输入。 if (radius > 0) area radius*radius*PI System. out. println ("The area for the +circle of radius n radius n is area)i else System. out. println("Negative input")i
if...else Example 如果半径大于0,则计算并显示圆的面积,否则提示无效输入。 if (radius >= 0) { area = radius*radius*PI; System.out.println("The area for the “ + “circle of radius " + radius + " is " + area); } else { System.out.println("Negative input"); }
If.Else语句流图 布尔表达 true false 语句(组)1 语句(组)2 下一条语句
If…Else语句流图 布尔表达式 语句(组)1 下一条语句 true false 语句(组)2
323主£语句的嵌套 GIf或if.le语句中的语句可以是任意合 法的Java语句—包括其他if或if.lse语 句 内层的语句称为嵌套在外层i语句中 嵌套的深度没有限制。 般i语句嵌套用于实现多重选择。 Else子句与同一块中离得最近if子句相匹
3.2.3 if 语句的嵌套 ) If或if…else语句中的语句可以是任意合 法的Java语句——包括其他if或if…else语 句。 )内层的if语句称为嵌套在外层if语句中。 嵌套的深度没有限制。 )一般if语句嵌套用于实现多重选择。 ) Else子句与同一块中离得最近if子句相匹 配