Task 3 of 10 · 0 solved · 10 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

1.6 Logic — and (&&) and or (||)

Lesson

&& (and) and || (or)

&& (AND) is true only when both sides are true. || (OR) is true when at least one side is true.


Worked example

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)?


What is (5 > 3) && (10 > 20)?


What is (5 > 3) || (10 > 20)?


Type exactly what this prints:

System.out.println((1 > 2) || (3 > 4));

True or false?


Task

Write the body of bothPositive that takes two int values a and b and returns true only when both are greater than 0.

For example, bothPositive(3, 5) returns true; bothPositive(3, -1) returns false.