102k views
3 votes
g what does the following piece of code do a) Print the duplicate elements in the array b) Print the element with maximum frequency c) Print the unique elements in the array d) None of the mentioned

1 Answer

4 votes

Answer:

a) Print the duplicate elements in the array

Step-by-step explanation:

I found this code:

This is two for cycle, where we make a comparison among two variables i and j to print duplicate elements.

for (int i=0; i < arr.length-1; i++)

{

for (int j = i+1; j < arr.length; j++)

{

if (( arr[i].equals(arr[j])) && (i != j))

{

System.out.println(arr[i])

}

}

}

User RichSmith
by
5.3k points