English

Explain the Relation Operator with the help of an example program.

Advertisements

Question

Explain the Relation Operator with the help of an example program.

Explain
Advertisements

Solution

In Java, Relational Operators are used to compare two values or expressions. These operators determine the relationship between two operands and return a Boolean value, either true or false, depending on the result of the comparison.

The various relational operators in Java are:

Operator

Description

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

==

Equal to

!=

Not equal to

Example Program:

class RelationalOperator 
{
    public static void main(String[] args) 
    {
        int a = 10;
        int b = 20;

        System.out.println(a > b);
        System.out.println(a < b);
        System.out.println(a >= b);
        System.out.println(a <= b);
        System.out.println(a == b);
        System.out.println(a != b);
    }
}

Output:

false
true
false
true
false
true
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 131]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 16. | Page 131
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×