public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return true && 1 / 0 != 1;
}
}
Exception in thread "main" java.lang.ArithmeticException: / by zero
at OperationDemo.test(OperationDemo.java:6)
at OperationDemo.main(OperationDemo.java:3)
public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return true & 1 / 0 != 1;
}
}
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Operator02Demo.test(Operator02Demo.java:6)
at Operator02Demo.main(Operator02Demo.java:3)
public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return false && 1 / 0 != 1;
}
}
false
public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return false & 1 / 0 != 1;
}
}
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Operator02Demo.test(Operator02Demo.java:6)
at Operator02Demo.main(Operator02Demo.java:3)
& <-- verifies both operands
&& <-- stops evaluating if the first operand evaluates tofalse
since the result will be false
public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return true || 1 / 0 != 1;
}
}
true
public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return true | 1 / 0 != 1;
}
}
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Operator02Demo.test(Operator02Demo.java:6)
at Operator02Demo.main(Operator02Demo.java:3)
public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return false || 1 / 0 != 1;
}
}
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Operator02Demo.test(Operator02Demo.java:6)
at Operator02Demo.main(Operator02Demo.java:3)
public class Operator02Demo {
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
return false | 1 / 0 != 1;
}
}
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Operator02Demo.test(Operator02Demo.java:6)
at Operator02Demo.main(Operator02Demo.java:3)
exprA | exprB <-- this means evaluate exprA then evaluate exprB then do the |.
exprA || exprB <-- this means evaluate exprA and only if this isfalse
then evaluate exprB and do the ||.
网友评论