Java Relational Operators

This article explains relational operators available in java.

 

Relational Operators

 

These operators compare the operands to determine their equality or ordering.

 

The outcome of relational operators is always a boolean value.

 

Operatormeaning
==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

 

Relational operators are mostly used in conditional statements as the conditional statements use a boolean expression for the condition.

 

This is shown in below example :

 

public class RelationalOperator {

  public static void main(String[] args) {
    // TODO Auto-generated method stub

    int a =1, b=2;
    if(a < b)
      System.out.println("A is less than B");
    if(a!=b)
      System.out.println("A is not equal to B");
  }

}


 

This program uses Less than(<) and Not equal to(!=) operators to check equality and ordering.

 

Here, note the difference between the equality operator (==) and the assignment operator. The assignment operator ( = ) is for assigning a value to a variable and == is for checking equality.

 

 

© 2015 – 2017, https:. All rights reserved. On republishing this post, you must provide link to original post

Leave a Reply.. code can be added in <code> </code> tags