if statement
The program executes a certain statement when a certain condition is established, and executes another statement in another case.
Examples are as follows
int x=34;
int y=20;
//判断x是否大于y
if(x>y){
//如果条件成立,则输出以下信息
System.out.println("x>y");
}
//判断x是否小于y
if(x<y){
//如果条件成立,则输出以下信息
System.out.println("x<y");
}
if...else statement
The program executes a certain statement when a certain condition is established, otherwise executes another statement.
Examples are as follows:
int x=34;
int y=20;
//判断x是否大于y
if(x>y){
//如果条件成立,则输出以下信息
System.out.println("x>y");
}
//除了x>y的情况,其他情况都输出以下信息
else{
System.out.println("x<=y");
}
The difference between if statement and if...else statement
Although both statements are used to express judgment, the if statement will only cover one case of judgment at a time, and if...else will include all cases of judgment.
Take the picture as an example