Skip to main content

//Logical Operator

 //Logical Operator


CODE

👇

  1. class logi //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 = 10; //initializing variables
  6. int b = 7;

  7. //Logical AND
  8. //we use also  Logical NOT
  9. if(!((a > b) && (a != b))) // !(a=50 > b=30) is False && (a=50 != b=30) is True; Therefore this statement is False.
  10.                               // when both statement are True then result will be True.
  11. {
  12. System.out.println("First statement is true"); //"System.out.println" use for print line.
  13. }
  14. else //when if condition false then else condition executed
  15. {
  16. System.out.println("First statement is false");
  17. }

  18. //Logical OR
  19. if((a > b) || (a != b)) // (a=50 < b=30) is False || (a=50 != b=30) is True; therefore this statement is True.
  20.                            //if one(or both) statement is True then result will be True, Otherwise it returns False.
  21.                           // '!'not is True statement consider False and False statement consider to True.
  22. {
  23. System.out.println("Second statement is true");
  24. }
  25. else
  26. {
  27. System.out.println("Second statement is false");
  28. }

  29. }
  30. }


👉Execute👈


//Output

/*

//Logical AND

First statement is false


//Logical OR

Second statement is true


*/



                                                                      //ThE ProFessoR