I want a core java program to find unique elements between two arrays. Example: Array1 - 9, 5,3,23,2,5 Array2 - 19, 5,3,23,24,53
output of unique elements from both of the array's should print as: 9, 2, 19, 24, 53
pls help me to write the program with accurate loops.
NOTE: Dont want to handle the same program using any of the collections and want to be done using only loops. Thanks
You have to use at least 2 loops.
public void uniqueM(int arrayA[], int arrayB[]){
boolean uniqueA = true, uniqueB = true;
int high_size = arrayA.length, low_size = arrayB.length;
if(arrayA.length < arrayB.length){
low_size = arrayA.length;
high_size = arrayB.length;
}
for(int i = 0; i < high_size; i++){
for(int j = 0; j < low_size;j++)
{
if(i < arrayA.length && arrayA[i] == arrayB[j]) uniqueA = false;
if(i < arrayB.length && arrayB[i] == arrayA[j]) uniqueB = false;
}
if(uniqueA && i < arrayA.length) System.out.println(arrayA[i]);
if(uniqueB && i < arrayB.length) System.out.println(arrayB[i]);
uniqueA = true;
uniqueB = true;
}
}