JAVA programs

Java Program Using Relational Operator

Relational operators that compare two operands value and return a boolean value as result. Following program demonstrate use of the relational operator in java.

Program

class EquityOperator

{

public static void main(String[] args)

    {

        int x=5;

        int y=10;

        if(x==y)

        System.out.println(" value of x is equal to value of y ");

        if(x!=y)

        System.out.println(" value of x is not equal to value of y ");

        if(x>y)

        System.out.println(" value of x is greater than value of y");

        if(x<y)

        System.out.println(" value of x is less than value of y ");

        if(x>=y)

        System.out.println(" value of x is greater than or equal to value of : ");

        if(x<=y)

        System.out.println(" value of x is less than or equal to value of y ");

    }

}

When Run The Program Following Output:

 value of x is not equal to value of y

 value of x is less than value of y

 value of x is less than or equal to value of y

Description

Relational operators are used in control statement like if, if- else, also used in loops.

Following are relational operators

== (equal to)  “this operator return result true if both operand values are equal”

!= (not equal to) “this operator return result true if both operand values not equal”

> (greater than)  “this operator return result true if value left operand is greater than right operand ”

 

< (less than)  “this operator return result true if value left operand is less than right operand  

>= (greater than or equal to)  “this operator return result true if value left operand greater than or equal to the value of right operand ”

 

<= (less than or equal to) “this operator return result true if value left operand is less than or equal to the value of right operand ”

Releted Programs

© 2017 codewmAll rights reserved.