Relational operators are binary operators. Java supports six relational operators which are as follows :
== //equal to
!= // not equal to
> // greater than
>= // greater than or equal to
< // less than
<= // less than or equal to
These operators are used when some comparisons will arise between two operands. For example, Let the value of a and b is 15 and 20 respectively.
If write a<b, then it is a case of comparison. This relational expression is evaluated as either true or false. So the value this expression is true. Let's see a program to understand these operators.
Class RelationalDemo
{
public static void main(String args[])
{
int x=10,y=15,z=20;
boolean p;
boolean q;
p=x<y;
q=y>z;
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(p);
System.out.println(q);
}
}
10
15
20
true
false