English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Program to Perform XOR on a Set of Booleans

First, let's take a look at the following boolean array to perform XOR on a set of booleans.

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

Now let's create a nested loop and perform XOR operations within it.

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

This is a complete example of displaying XOR on a set of boolean values.

Example

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 Result

false
false
true
false
false
true
true
true
false