2022-04-24 13:13:26
// Java program to find the XOR of
// all elements in the array
class GFG {
// Function to find the XOR of
// all elements in the array
static int xorOfArray(int arr[], int n)
{
// Resultant variable
int xor_arr = 0;
// Iterating through every element in
// the array
for (int i = 0; i < n; i++) {
// Find XOR with the result
xor_arr = xor_arr ^ arr[i];
}
// Return the XOR
return xor_arr;
}
// Driver Code
public static void main (String[] args)
{
int arr[] = { 3, 9, 12, 13, 15 };
int n = arr.length;
//CodingSolution
System.out.println(xorOfArray(arr, n));
}
}
Java
Prifix XOR code
Telegram - t.me/codingsolution_IT
17.1K views10:13