Task 1 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 — comparisons give a boolean

Lesson

Comparisons and logic

This module is about asking yes/no questions in code. The answers are boolean values, and you combine them with and, or, and not.


Comparison operators

The operators > < >= <= == != compare two values and give a boolean. == tests equality (not =, which assigns); != means not equal.


Worked example

5 > 3     // true
4 == 4    // true
3 != 5    // true
4 <= 3    // false

▶ Try it: run this, then change something and run it again.



What is the value of 5 > 3?


What is the value of 3 != 5?


Type exactly what this prints:

System.out.println(4 <= 3);

Sort each comparison by its value.


Task

Write the body of isEven that takes an int n and returns true when n is even, and false otherwise.

For example, isEven(4) returns true; isEven(7) returns false.