Introduction to Java

Relational Operators

It looks like you're getting the hang of this! Let's explore another set of useful operators available in Java known as relational operators.

Relational operators compare data types that have a defined ordering, like numbers (since numbers are either smaller or larger than other numbers).

Relational operators will always return a boolean value of true or false.

Here are a few relational operators:

  1. < : less than.
  2. <=: less than or equal to.
  3. >: greater than.
  4. >=: greater than or equal to.

A relational operator is placed between the two operands (the terms that you want to compare using the relational operator). The result of a relational operation is printed out in the following statement:

System.out.println(5 < 7);

The example above will print out true because the statement "5 is less than 7" is true.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.