1.&&左右两侧皆进行运算
public class AndTest {
public static void main(String args[]){
int i = 0;
if(true && (i++ == 1)){
System.out.println("the if result is " + i);
}else{
System.out.println("the else result is " + i);
}
}
}
结果:the else result is 1
i++先取i值运算之后i自动增1
2.||先进行逻辑或左侧运算,若结果为true,不进行右侧运算!
public class OrTest {
public static void main(String args[]){
int i = 0;
if(true || (++i == 1)){
System.out.println("the if result is " + i);
}else{
System.out.println("the else result is " + i);
}
}
}
结果:the if result is 0
欢迎加我的qq技术群425783133