English

Explain the following operator with an example program: Relational Operator

Advertisements

Question

Explain the following operator with an example program:

Relational Operator

Code Writing
Explain
Advertisements

Solution

A Relational Operator in Java is used to compare two values or expressions. It determines the relationship between them and returns a Boolean value, either true or false.

The relational operators in Java are greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=), equal to (==) and not equal to (!=).

Example:

class RelationalOperator
{
    public static void main(String[] args)
    {
        int a = 10, 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 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 31. (b) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×