Home Java Jdk7 Relational Operators in java 7
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Relational Operators in java 7

Advertisement
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.

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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 19, 2012

Related Tutorials

Ask Questions?    Discuss: Relational Operators in java 7  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com