Java Program to perform an XOR on a set of Booleans


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

118 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements