Java : Relational Operators

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 &gt; j is " + (i &gt; j));
	    System.out.println("i = j));
	    System.out.println("i &lt;= j is &quot; + (i &lt;= j));
	    System.out.println(&quot;i == j is &quot; + (i == j));
	    System.out.println(&quot;i != j is &quot; + (i != j));

	    System.out.println(&quot;(i &lt; 10) &amp;&amp; (j &lt; 10) is &quot; + ((i &lt; 10) &amp;&amp; (j &lt; 10)));
	    System.out.println(&quot;(i &lt; 10) || (j &lt; 10) is &quot; + ((i &lt; 10) || (j &lt; 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