Skip to content

Relational operators

Relational operators compare two values and return a boolean result (true or false). They are used in conditions like if, while, etc.

OperatorDescriptionExample
<Less thana < b
<=Less than or equala <= b
>Greater thana > b
>=Greater than or equala >= b

Examples:

int age = 18;
if (age >= 18) {
System.out.println("Adult");
}
double score = 85.5;
if (score < 60) {
System.out.println("Fail");
}

Important: Relational operators work with numeric types only (including char). For objects, use methods like compareTo().

char c1 = 'A', c2 = 'B';
System.out.println(c1 < c2); // true (based on Unicode value)