The difference between short-circuit and && and and &
: No matter whether the conditions are correct or not, all are executed.
Short-circuit and: A&&B, if A is false, the expression will end directly, and B will not be executed.
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);
}
}
The difference between short-circuit or || and or|
Or: No matter whether the conditions are correct or not, all are executed.
Short-circuit or: A||B, if A is true, the expression will end directly, and B will not be executed.
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 novice, hope for guidance