javatutelearn.com

Easy Learning


Home

Search Javatutelearn.com :




Java Operators


3. Relational Operators


Relatiional operators determine the relationship between operands. The result of these operations is a boolean value. Following table shows list of relational opeators available in Java.
Operator Purpose
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Relational Operators Example

Example is demostrating Relational operators usage.
class RelOp {
public static void main(String args[]) {
int a=30; 
int b=30;

System.out.println("Value of a is " + a);
System.out.println("Value of b is " + b);
if (a == b){
	System.out.println("a is equal to b");
}

a = 10;
b = 20;
System.out.println("Value of a is " + a);
System.out.println("Value of b is " + b);
if (a != b){
	System.out.println("a is not equal to b");
 }

System.out.println("Value of a is " + a);
System.out.println("Value of b is " + b);
 if (b > a){
	System.out.println("b is greater than a");
 }

System.out.println("Value of a is " + a);
System.out.println("Value of b is " + b);
 if (a < b){
	System.out.println("a is less than b");
 }

a = 50;
b = 40;
System.out.println("Value of a is " + a);
System.out.println("Value of b is " + b);

if (a >= b){
	System.out.println("a is greater than b");
 }

System.out.println("Value of a is " + a);
System.out.println("Value of b is " + b);

 if (b <= a){
	System.out.println("b is less than a");
 }
 }
}
 

Output of the program

Value of a is 30
Value of b is 30
a is equal to b
Value of a is 10
Value of b is 20
a is not equal to b
Value of a is 10
Value of b is 20
b is greater than a
Value of a is 10
Value of b is 20
a is less than b
Value of a is 50
Value of b is 40
a is greater than b
Value of a is 50
Value of b is 40
b is less than a


© Copyright 2016-2024 by javatutelearn.com. All Rights Reserved.