Friday, 30 December 2016

Logical Operators In Java Example

package com.kt4study.corejava.operators;

/**
 @author kt4study.blogspot.co.uk
 
 */

public class LogicalOperatorsExample {
  
  public static void logicalOperators() {
    
    boolean a = true;
    boolean b = false;
    boolean result;
    
    // && Logical AND example
    result = (a && b);
    System.out.println("Logical AND  (a && b) :: " + result);
    
    // || Logical OR example
    result = (a || b);
    System.out.println("Logical OR  (a || b) :: " + result);
        
    // ! Logical Not example
    result = !(a || b);
    System.out.println("Logical NOT  !(a || b) :: " + result);
  }

  public static void main(String[] args) {
    LogicalOperatorsExample.logicalOperators();
  }

}

Output →

Logical AND (a && b) :: false
Logical OR (a || b) :: true
Logical NOT !(a || b) :: false

No comments:

Post a Comment