if statement
优质
小牛编辑
138浏览
2023-12-01
if语句由一个布尔表达式后跟一个或多个语句组成。
语法 (Syntax)
以下是if语句的语法 -
if(Boolean_expression) {
// Statements will execute if the Boolean expression is true
}
如果布尔表达式的计算结果为true,那么将执行if语句中的代码块。 如果没有,将执行if语句结束后(在结束大括号之后)的第一组代码。
流程图 (Flow Diagram)

例子 (Example)
public class Test {
public static void main(String args[]) {
int x = 10;
if( x < 20 ) {
System.out.print("This is if statement");
}
}
}
这将产生以下结果 -
输出 (Output)
This is if statement.