Jul 17, 2014

Java Logical Operators ( And && Or || )

If You Have To Check Two Variable Values To Given  Two Values, You May Some Time Write Many If Else Statements To Check For Many Variable Values.Without Writing Many If Else Statement You Can Check Many Values That Mean Many If Else Statements In A Single Statement By Using AND or OR Logical Operators.  

You Can Use AND(&&) Logical Operator If You Want To Do Something After Every Operator Gets True.

You Can Use OR(||) Logical Operator If You Want To Do Something After Any Of The Operator Gets True.

Following Example Demonstrate How AND , OR Operators Work.

class EasyCodeStuff {
   public static void main(String args[]){
     
      int No1 = 10;
      int No2 = 20;

      //AND Logical Opearator

      if (No1 == 10 && No1 == 20){
         System.out.println("No1 is Equal To 10 AND No2 is Equal To 20");
      }else{
         System.out.print("No1 is Not Equal To 10 OR No2 is Not Equal To 20");
      }
      
      //OR Logical Operator
      if (No1 == 10 || No1 == 20){
         System.out.println("No1 is Equal To 10 OR No2 is Equal To 20");
      }else{
         System.out.print("No1 is Not Equal To 10 AND No2 is Not Equal To 20");
      }
   }
}    



No comments:

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...