Boolean Operator In Java Example

Chapter: Operators Last Updated: 15-07-2016 14:02:17 UTC

Program:

            /* ............... START ............... */
                
public class JavaBooleanOperatorExample {
	public static void main(String args[]) {
		boolean a = true;
		boolean b = false;
		boolean c = a | b;
		boolean d = a & b;
		boolean e = a ^ b;
		boolean f = (!a & b) | (a & !b);
		boolean g = !a;
		System.out.println(" a = " + a);
		System.out.println(" b = " + b);
		System.out.println(" a|b = " + c);
		System.out.println(" a&b = " + d);
		System.out.println(" a^b = " + e);
		System.out.println("!a&b|a&!b = " + f);
		System.out.println(" !a = " + g);
	}
}

                /* ............... END ............... */
        

Output

a = true
b = false
a|b = true
a&b = false
a^b = true
!a&b|a&!b = true
!a = false

Notes:

  • Boolean in java assign two values true or false.
  • Boolean logical operators are : | , & , ^ , ! , || , && , == , != .

Tags

Boolean Operator, Java

Similar Programs Chapter Last Updated
Java Left Shift Operator Operators 04-09-2018
Java Addition Operator Operators 18-05-2017
Java Right Shift Operator Operators 13-12-2016
Prefix Operator In Java Example Operators 19-06-2016
Logical Operators In Java Example Operators 17-06-2016
Operator Precedence In Java Examples Operators 17-06-2016
Ternary Operators In Java Example Operators 15-07-2016
Relational Operators In Java Example Operators 11-06-2016
Modulus Operators In Java Example Operators 15-07-2016
Increment And Decrement In Java Example Operators 15-07-2016
Bitwise Operator In Java Example Operators 16-06-2017
Assignment Operation In Java Example Operators 06-04-2016
Arithmetic Operation In Java Example Operators 11-06-2016

1