&& (AND) is true only when both sides are true. || (OR) is true when at least one side is true.
&&
||
true && true // true true && false // false true || false // true false || false // false
▶ Try it: run this, then change something and run it again.
What is (5 > 3) && (2 > 1)?
(5 > 3) && (2 > 1)
What is (5 > 3) && (10 > 20)?
(5 > 3) && (10 > 20)
What is (5 > 3) || (10 > 20)?
(5 > 3) || (10 > 20)
Type exactly what this prints:
System.out.println((1 > 2) || (3 > 4));
True or false?
Write the body of bothPositive that takes two int values a and b and returns true only when both are greater than 0.
bothPositive
int
a
b
true
For example, bothPositive(3, 5) returns true; bothPositive(3, -1) returns false.
bothPositive(3, 5)
bothPositive(3, -1)
false