Java Reference
In-Depth Information
Relational Operator
When there is a need to compare two quantities, relational operators are used. An expres-
sion like p>q or p>=30 having a relational is known as relational expression. The output of
a relational expression is either TRUE or FALSE. There are 6 relational operators in Java
which are given in the following table.
Operator
Meaning
==
Is equal to
!=
Not equal to
<
Less than
<=
Less than or equal to
>
Greater than
>=
Greater than or equal to
Example to demonstrate the relational operators:
public class Test {
public static void main(String args[]) {
int p = 10;
int q = 20;
System. out. println ("p == q = " + (p == q) );
System.out.println ("p != q = " + (p != q) );
System.out.println ("p > q = " + (p > q) );
System.out.println ("p < q = " + (p < q) );
System.out.println ("q >= p = " + (q >= p) );
System.out.println ("q <= p = " + (q <= p) );
}
}
Search WWH ::




Custom Search