A Developer Gateway To IT World...

### Amazon asked Java IQ: Write a program to find duplicates from array of prime numbers.

Write a program to find duplicates from array of prime numbers.

# Amazon IQ

3.Write a program to find duplicates from array of prime numbers.

/*Write a program to find duplicates from the array of prime numbers.*/
public class TestAPrime_Array {

//create method for the duplicate
public int[] allDuplicateFromArray(int prime_array[])
{
System.out.println("Start checking duplicate element in array...");
int[] new_prime_array =new int[prime_array.length];
for(int i=0; i<prime_array.length; i++)
{
for(int j=i+1; j<prime_array.length; j++)
{
if(prime_array[i]==prime_array[j])
{
new_prime_array[i]=prime_array[i];
}
}
}
return new_prime_array;
}
public static void main(String[] args) {
int a[]= {3,5,7,13,17,5,3};

//create object to access method
TestAPrime_Array  obj=new TestAPrime_Array();
int[] b=obj.allDuplicateFromArray(a);

System.out.println("Lets Print duplicate:-");
for(int i=0; i<b.length; i++)
{
System.out.println(b[i]);
}

}

}

OUTPUT:
Start checking duplicate element in array...
Lets Print duplicate:-
3
5
0
0
0
0

0