Java Program to perform an XOR on a set of Booleans

Java 8Object Oriented ProgrammingProgramming

To perform XOR on a set of Booleans, firstly let us consider the following Boolean array.

boolean[] arr = { true, true, false };

Let us now create a nested loop and within that perform XOR operation.

for (boolean one : arr) {
   for (boolean two: arr) {
      // XOR
      boolean res = one ^ two;
   }
}

Here is the entire example to displayXOR on a set of Booleans.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      // boolean array
      boolean[] arr = { true, true, false };
      for (boolean one : arr) {
         for (boolean two: arr) {
            // XOR
            boolean res = one ^ two;
            System.out.println(res);
         }
      }
   }
}

Output

false
false
true
false
false
true
true
true
false
raja
Published on 12-Nov-2018 10:30:44
Advertisements