Skip to main content

//Relational(Comparison) Operator

 //Relational(Comparison) Operator


  1. class reop //class Declaration; class name same as file name. when save in local file.
  2. {
  3. public static  void  main(String args[]) //Main Method
  4. {
  5. int  a = 21; //initializing variables
  6. int b = 10;
  7.     
  8. //equal to
  9. System.out.println("a is equal to b: "+(a == b)); // (a=21 == b=10) is False; Therefore a is not equal to b.
  10.                                                         //the two given values are equal to each other then result will be True, Otherwise it returns False.
  11. //not equal to
  12. System.out.println("a is not equal to b: "+(a != b)); // (a=21 != b=10) is True; Therefore a is not equal to b.
  13.                                                             // '!'not is True statement consider False and False statement consider to True.

  14. //grater than
  15. System.out.println("a is grater than b: "+(a > b)); //(a=21 > b=10) is True; Therefore a is grater than b.
  16.                                                           //the first value is grater than the second value then result will be True, Otherwise it returns False.
  17.         
  18. //less than    
  19.         System.out.println("a is less  than b: "+(a < b)); //(a=21 < b=10) is False; Therefore a is not less than b.
  20.                                                                //the first value is less than the second value then result will be True, Otherwise it returns False.
  21. //grater than or equal to
  22. System.out.println("a is grater than or equal to b: "+(a >= b)); //(a=21 >= b=10) is True; Therefore a is grater than or equal to b.
  23.                                                                   //the first value is grater than or equal to the second value then result will be True, Otherwise it returns False.

  24. //less than or equal to
  25.         System.out.println("a is less  than or equal to b: "+(a <= b)); //(a=21 <= b=10) is False; Therefore a is not less than or equal to  b.
  26.                                                                        //the first value is less than or equal to  the second value then result will be True, Otherwise it returns False.
  27. }

  28. }


👉Execute👈


//Output

/*

a is equal to b: false

a is not equal to b: true

a is grater than b: true

a is less  than b: false

a is grater than or equal to b: true

a is less  than or equal to b: false

*/





                                                                         //ThE ProFessoR