Java Relational Operators: Examples and Usage

Rumman Ansari   Software Engineer   2024-07-04 03:24:09   7423 Share
Subject Syllabus DetailsSubject Details 10 MCQ
☰ TContent
☰Fullscreen

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 . . .