Relational Operator In Java

Definition: Relational Operators ? Use of the Relational Operators

The relational operators are binary operators .In java, Relational operators specify the relation between two variables by comparing them. There are 5 relational operators in Java.

Use of the Relational Operators

A relational operator tests data values against one another.

You can only compare similar data types. (It makes no sense to compare a char to a float.

All relational operators return either a 1 (meaning true) or a 0 (false.)

You will use the relational operators to test whether a condition is true or false and act accordingly.

Relational Operators

Operator Description Example
== Is equal to a==b
!= Is not equal to a!=b
> Greater than a>b
< Less than a<b
>= Greater than or equal to a>=b
<= Less than or equal to a<=b

Example 1:

Output :

 a == b = false
 a != b = true
 a > b = false
 a < b = true
 b >= a = true
 b <= a = false

Example 2:

Output :

 Please Enter two integer Value: 6
 a is Not equal to b