Relational Operators in Java

Relational operators in java are used to check the relationship between two operands. Relational operators determines whether one operator is  greater than, less than, equal to, or not equal to another operand.

OperatorDescription of the Operator
==equals to.
For example:
int x = 5, y=10;
System.out.println(x == y); //will return false because x is not equal to y.
>greater than.
For example:
int x = 5, y=10;
System.out.println(x > y); //will return false because x is not greater than y.
However, if we write
System.out.println(y > x); //will return true because y is greater than x.
<less than.
For example:
int x = 5, y=10;
System.out.println(x < y); //will return true because x is less than y.
However, if we write
System.out.println(y < x); //will return true because y is not less than x.
>=greater than equals to.
For example:
int x = 5, y=10;
System.out.println(x > =y); //will return false because x is not greater than or equals to y.
However, if we write
System.out.println(y > x); //will return true because y is greater than x.
<=less than equals to.
For example:
int x = 5, y=10;
System.out.println(x < =y); //will return true because x is less than y.
However, if we write
System.out.println(y < =x); //will return true because y is not less than or less than x.
!=not equals to.
For example:
int x = 5, y=10;
System.out.println(x != y); //will return true because x is not equal to y.

You can find the code here

Rutu Shah