Relational Operators in Java


Relational Operators are a bunch of binary operators that are used to check for relations between two operands including equality, greater than, less than, etc. They return a boolean result after the comparison and are extensively used in looping statements as well as conditional if-else statements and so on.Relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.

Operatoruses
== equality operator
!= non-equality operator
< less than operator
> greater than operator
<= less than or equal to operator
>= greater than or equal to operator

Source Code

public class relational {
    public static void main(String args[])
    {
        int a=100,b=50;
        System.out.println("Equal to : "+(a==b));
        System.out.println("Not Equal to : "+(a!=b));
        System.out.println("Greater than : "+(a>b));
        System.out.println("Less than : "+(a<b));
        System.out.println("Greater than or equal to : "+(a>=b));
        System.out.println("Less than or equal to : "+(a<=b));
    }
}
 

Output

Equal to : false
Not Equal to : true
Greater than : true
Less than : false
Greater than or equal to : true
Less than or equal to : false
To download raw file Click Here

Basic Programs