短路与&&和与&的区别
与:不管条件对不对,全部执行完
短路与:A&&B,若A为false则直接结束这条表达式,不会执行B
package JavaClass;
public class _02赋值运算符 {
public static void main(String[] args) {
int a = 1;
int b = 1;
// boolean res0 = a>=b||b++>1; // 结果b=1
boolean res1 = a>=b|b++>1; // 结果b=2
System.out.println(b);
}
}
短路或||和或|的区别
或:不管条件对不对,全部执行完
短路或:A||B,若A为true则直接结束这条表达式,不会执行B
package JavaClass;
public class _02赋值运算符 {
public static void main(String[] args) {
int a = 1;
int b = 1;
// boolean res0 = a<b&&b++>1; // b=1
boolean res1 = a<b&b++>1; // b=2
System.out.println(b);
}
}
Java小白,望大佬指点