Perform XOR on a Set of Booleans in Java



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
Updated on: 2020-06-26T10:11:38+05:30

166 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements