if/else 条件
if...else...和if语句是不同的运行方式:
public class MyFirstApp{
public static void main(String[] args){
int x=3;
if(x==10){
System.out.println("x must be 10");
}else{
System.out.println("x must not be 10");
}
if(x<4){
System.out.println("Gently");
}
System.out.println("this line runs no matter what");
}
}
运行结果:
if...else...中只运行其中一个,但是第二个if分支后的语句,跟if没有关系,所以正常运行。
注:观察好运行步骤。
if()中的表达式的值不是true就是false

浙公网安备 33010602011771号