只要第一个条件满足,就不会走下面的判断了。
代码如下:
public class Test {
public static void main(String args[]){
int x = 30;
int y = 20
if( x == 10 ){
System.out.print("Value of X is 10");
}else if( y == 20 ){
System.out.print("Value of Y is 20");
}else if( x == 30 ){
System.out.print("Value of X is 30");
}else{
System.out.print("这是 else 语句");
}
}
}
输出为:Value of Y is 20
并不会输出:Value of X is 30