Complete the code to initialize the result variable to zero.
int result = [1];We start with zero because XOR with zero leaves the number unchanged.
Complete the for-loop header to iterate over the array named nums.
for (int [1] = 0; i < nums.length; i++) {
The variable i is commonly used as the loop counter in Java.
Fix the error in the XOR operation inside the loop.
result = result [1] nums[i];XOR operator in Java is '^'. It is used to find the non-repeating element.
Fill both blanks to complete the method signature and return statement.
public static int [1](int[] nums) { int result = 0; for (int i = 0; i < nums.length; i++) { result = result ^ nums[i]; } return [2]; }
The method is named findUnique and returns the variable result which holds the unique element.
Fill all three blanks to complete the main method that tests the unique element finder.
public static void main(String[] args) {
int[] nums = {2, 3, 5, 4, 5, 3, 4};
int unique = [1](nums);
System.out.println("Unique element is: " + [2]);
// Expected output: Unique element is: [3]
}The method findUnique is called with nums array, result stored in unique, and printed. The unique element is 2.
