-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicatearray.java
More file actions
37 lines (35 loc) · 809 Bytes
/
Duplicatearray.java
File metadata and controls
37 lines (35 loc) · 809 Bytes
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
32
33
34
35
36
37
import java.util.*;
class functions{
int duplicate(int arr[]){
int count=0,i,j,p=0;
for(i=0;i<arr.length;i++){
for(j=0;j<arr.length;j++){
if(arr[i]==arr[j]){
count=count+1;
}
}
if(count>=2){
p=arr[i];
break;
}
else
count=0;
}
return p;
}
}
class Duplicatearray{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
functions f=new functions();
System.out.println("enter size");
int size=sc.nextInt();
int arr1[]=new int[size];
for(int i=0;i<size;i++){
System.out.println("enter the element");
arr1[i]=sc.nextInt();
}
int k=f.duplicate(arr1);
System.out.println(k);
}
}