No announcement
 

Relational Operators

Relational operators supported by Java are:-

  1. Equality, ==
    It is used to test values for equality. 
  2. Inequality, !=
    It is used to test value for inequality.
  3. Greater than, >
    It is used to test whether a given value is greater than some other value.
  4. Less than, <
    It is used to test whether a given value is less than some other value.
  5. Greater than or equal, >=
    It is used to test whether a given value is greater than or equal to some other value.
  6. Less than or equal, <=
    It is used to test whether a given value is less than or equal to some other value.

Example:

RelationalOperatorsDemo.java

package com.codingnous.tutorial;

public class RelationalOperatorsDemo {

	public static void main(String[] args) {

		// Declare two variable for demo
		int value1 = 1250, value2 = 375;

		// Lets do relational check
		System.out.println("Is " + value1 + " == " + value2 + " ? : " + (value1 == value2));
		System.out.println("Is " + value1 + " != " + value2 + " ? : " + (value1 != value2));
		System.out.println("Is " + value1 + " > " + value2 + " ?  : " + (value1 > value2));
		System.out.println("Is " + value1 + " < " + value2 + " ?  : " + (value1 < value2));
		System.out.println("Is " + value1 + " >= " + value2 + " ? : " + (value1 >= value2));
		System.out.println("Is " + value1 + " <= " + value2 + " ? : " + (value1 <= value2));
	}

}

Output
Is 1250 == 375 ? : false Is 1250 != 375 ? : true Is 1250 > 375 ? : true Is 1250 < 375 ? : false Is 1250 >= 375 ? : true Is 1250 <= 375 ? : false