Relational Operators in Java

Java Relational Operators are a bunch of binary operators used to check for relations between two operands, including equality, greater than, less than, etc.

The general format of representing relational operator is: 

Syntax:

variable1 relation_operator variable2

Operator 1: ‘Equal to’ operator (==)

This operator is used to check whether the two given operands are equal or not. The operator returns true if the operand at the left-hand side is equal to the right-hand side, else false. 

Syntax: 

var1 = = var2

Example


Operator 2: ‘Not equal to’ Operator(!=)

This operator is used to check whether the two given operands are equal or not. It functions opposite to that of the equal-to-operator. It returns true if the operand at the left-hand side is not equal to the right-hand side, else false. 

Syntax:

 var1 != var2 ;

 

Operator 3: ‘Greater than’ operator(>)

This checks whether the first operand is greater than the second operand or not. The operator returns true when the operand at the left-hand side is greater than the right-hand side. 

Syntax:

 var1 > var2;

Operator 4: ‘Less than’ Operator(<)

This checks whether the first operand is less than the second operand or not. The operator returns true when the operand at the left-hand side is less than the right-hand side. It functions opposite to that of the greater-than operator. 

Syntax:

var1 < var2 ;

 

Operator 5: Greater than or equal to (>=)

This checks whether the first operand is greater than or equal to the second operand or not. The operator returns true when the operand at the left-hand side is greater than or equal to the right-hand side. 

Syntax:

 var1 >= var2;

Operator 6: Less than or equal to (<=)

This checks whether the first operand is less than or equal to the second operand or not. The operator returns true when the operand at the left-hand side is less than or equal to the right-hand side. 

Syntax:

 var1 <= var2;


 

 

No comments:

Post a Comment