Finding duplicate element in Array

Java program to find duplicate element in Array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
package com.spy.javaforlearn;
 
public class FindDuplicate 
{
 
	public static void main(String[] args) {
 
 
	int[] number={10,20,14,10,20,30,35,27,35};
 
 
	System.out.println("Duplicate element");
	for(int i=0;i<number.length;i++)
	{
 
		for(int j=i+1;j<number.length;j++)
		{
 
			if(number[i]==number[j] && i!=j)
			{
 
				System.out.println(number[i]);
 
			}
		}
 
	  }
 
	}	
}

Output:

1
2
3
4
5
 
Duplicate element
10
20
35

Leave a Reply

Your email address will not be published. Required fields are marked *