public class BooleanOperations {
// Method for AND operation
public static boolean andOperation(boolean a, boolean b) {
return a && b;
}
// Method for OR operation
public static boolean orOperation(boolean a, boolean b) {
return a || b;
}
// Method for XOR operation
public static boolean xorOperation(boolean a, boolean b) {
return a ^ b;
}
// Method for NOT operation
public static boolean notOperation(boolean a) {
return !a;
}
public static void main(String[] args) {
boolean a = true;
boolean b = false;
System.out.println(“a is”+a);
System.out.println(“b is”+b);
System.out.println(“Boolean AND Operation:”);
System.out.println(“true AND false (a,b) = ” + andOperation(a, b));
System.out.println(“true AND true (a,a) = ” + andOperation(a, a));
System.out.println(“false AND false (b,b)= ” + andOperation(b, b));
System.out.println(“\nBoolean OR Operation:”);
System.out.println(“true OR false (a,b)= ” + orOperation(a, b));
System.out.println(“true OR true (a,a)= ” + orOperation(a, a));
System.out.println(“false OR false (b,b)= ” + orOperation(b, b));
System.out.println(“\nBoolean XOR Operation:”);
System.out.println(“true XOR false (a,b)= ” + xorOperation(a, b));
System.out.println(“true XOR true (a,a)= ” + xorOperation(a, a));
System.out.println(“false XOR false (b,b)= ” + xorOperation(b, b));
System.out.println(“\nBoolean NOT Operation:”);
System.out.println(“NOT true (a)= ” + notOperation(a));
System.out.println(“NOT false (b)= ” + notOperation(b));
}
}
Output
a istrue
b isfalse
Boolean AND Operation:
true AND false (a,b) = false
true AND true (a,a) = true
false AND false (b,b)= false
Boolean OR Operation:
true OR false (a,b)= true
true OR true (a,a)= true
false OR false (b,b)= false
Boolean XOR Operation:
true XOR false (a,b)= true
true XOR true (a,a)= false
false XOR false (b,b)= false
Boolean NOT Operation:
NOT true (a)= false
NOT false (b)= true
Leave a Reply