Relational Operator example in Java Programming Language

Rumman Ansari   Software Engineer   2022-03-03   7497 Share
☰ Table of Contents

Table of Content:


Below program is a simple example which demonstrates the relational operators. Copy and paste the following Java program in RelationalOperator.java file, and compile and run this program

Arithmetic Operators

 public class RelationalOperator {

   public static void main(String args[]) {
      int p = 5;
      int q = 10;

      System.out.println("p == q = " + (p == q) );
      System.out.println("p != q = " + (p != q) );
      System.out.println("p > q = " + (p > q) );
      System.out.println("p < q = " + (p < q) );
      System.out.println("q >= p = " + (q >= p) );
      System.out.println("q <= p = " + (q <= p) );
   }
}

Output

p == q = false
p != q = true
p > q = false
p < q = true
q >= p = true
q <= p = false
Press any key to continue . . .