In this tutorial you will learn about the Java Relational Operators and its application with practical example.
Java Relational Operators
Relational Operators are used to evaluating a comparison between two operands. The result of a relational operation is a Boolean value that can only be true or false. Relational Operators are also referred to as comparison operators.
Let variable a hold 20 and variable b holds 10, then −
Operator | Description | Example |
---|---|---|
> |
greater than |
a>b returns TRUE |
< |
Less than |
a<b returns FALSE |
>= |
greater than or equal to |
a>=b returns TRUE |
<= |
less than or equal to |
a<=b returns FALSE |
== |
is equal to |
a==b returns FALSE |
!= |
not equal to |
a!=b returns TRUE |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class Main { public static void main(String[] args) { int a= 20; int b= 10; System.out.println("W3Adda - Java Relational Operators"); if(a > b) { System.out.println("a is greater than b."); }else{ System.out.println("b is greater than a."); } } } |
When you run the above java program, you will see the following output.
Output:-