Java-Relational Operators

Relational Operators

We often compare two quantities, and depending on their relation, take certain decisions. For example, we may compare the age of two persons, or the price of two items, and so on. These comparisons can be done with the help of relational operators. The value of relational expression is either true or false.

Operator Meaning
== is equal to
!= is not equal to
< is less than
<= is less than or equal to
> is greater than
>= is greater than or equal to



Program Source

 class Javaapp {

   public static void main(String[] args) {
        boolean b = 100==100;
        System.out.println("100 Equal to 100 is "+b);
        b = 50!=50;
        System.out.println("50  Not equal to 50 is "+b);
        b = 15>50;
        System.out.println("15  Greater than 50 is "+b);
        b = 20<50;
        System.out.println("20  Less than 50 is "+b);
        b = 50>=30;
        System.out.println("50  Greater than or equal to 30 is "+b);
        b = 40<=30;
        System.out.println("40  Less than or equal to 30 is "+b);

Leave a Comment