说明:
A one-way if statement executes an action if and only if the condition is true.
语法格式:
if (boolean-expression) {
statement(s);
}
对应程序流程图:
代码片段举例:
// ① 求圆的面积:S=πR²
if (radius >= 0) {
area = radius * radius *Math.PI;
System.out.println("半径为" +
radius +"的圆面积是" + area);
}