Relational operators also called as comparison operators used to check the relation between two operands and return the result as a boolean value.
For Example:
x < y (x is less than y) this expression will return the result as true if x is less than y, otherwise false.
See Also :
Here is a complete list of relational operators:
Relational Operators | Description |
> | greater than |
>= | greater than or equal to |
== | equal to |
!= | not equal to |
<= | less than or equal to |
< | less than |
Relation Operator Example
import java.util.Random; public class RelationalOperatorTest { public static void main(String[] args) { Random rand = new Random(); int i = rand.nextInt(200); int j = rand.nextInt(200); System.out.println("i = " + i); System.out.println("j = " + j); System.out.println("i > j is " + (i > j)); System.out.println("i = j)); System.out.println("i <= j is " + (i <= j)); System.out.println("i == j is " + (i == j)); System.out.println("i != j is " + (i != j)); System.out.println("(i < 10) && (j < 10) is " + ((i < 10) && (j < 10))); System.out.println("(i < 10) || (j < 10) is " + ((i < 10) || (j < 10))); } }
Output
i = 185
j = 170
i > j is true
i = j is true
i <= j is false
i == j is false
i != j is true
(i < 10) && (j < 10) is false
(i < 10) || (j < 10) is false
You must log in to post a comment.