Relational Operators in java 7

In this section you will learn about the Equality and Relational operators. This is one type of operators.

Relational Operators in java 7

In this section you will learn about the Equality and Relational operators. This is one type of operators.

Relational Operators in java 7

Relational Operators in java 7

In this section you will learn about the Equality and Relational operators. This is one type of operators.

Equality and Relational Operators :

Equality operator checks for equality of operands. The relational operators checks operand relations like greater than, less than, equal to, not equal to.

== (Equal to) This operator is used to check the equality of operands. If the condition is satisfied it returns true otherwise false. (X==Y)

!=(Not equal to) It checks that the operands are not equal. If the condition is satisfied it returns true otherwise false.(X!=Y)

> (Greater than) This operator checks whether left operand is greater than or not. If greater returns true otherwise false. (X>Y)

< (Less than) This operator checks whether left operand is less than or not. If less returns true otherwise false. (X<Y)

>=(Greater than equal to) This operator checks whether left operand is greater than equal to or not. If satisfied returns true otherwise false. (X>=Y)

<=(Less than equal to) This operator checks whether left operand is less than equal to or not. If satisfied returns true otherwise false. (X<=Y)

Example :

package operator;

class RelationalOperator {
	public static void main(String[] args) {
		int x = 10;
		int y = 20;
		boolean flag;

		System.out.println("X = " + x);
		System.out.println("Y = " + y);
		
		flag = (x == y); // Equal to operator
		System.out.println("X==Y : " + flag);
		
		flag = (x != y); // Not equal to operator
		System.out.println("X!=Y : " + flag);
		
		flag = (x > y); // Greater than operator
		System.out.println("X > Y : " + flag);
		
		flag = (x < y); // Less than operator
		System.out.println("X < Y : " + flag);
		
		flag = (x >= y); // Greater than equal to operator
		System.out.println("X>=Y : " + flag);
		
		flag = (x <= y); // Less than equal to operator
		System.out.println("X<=Y : " + flag);
	}
}

Output :

X = 10
Y = 20
X==Y : false
X!=Y : true
X > Y : false
X < Y : true
X>=Y : false
X<=Y : true