-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDuplicate.java
More file actions
49 lines (37 loc) · 881 Bytes
/
ArrayDuplicate.java
File metadata and controls
49 lines (37 loc) · 881 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
38
39
40
41
42
43
44
45
46
47
48
49
package yayyy;
import java.util.Scanner;
public class ArrayDuplicate {
public static int duplicate(int[] arr){
int b=0;//in which we will store the duplicate elements
int count=0;//no of times element occur
for(int i=0;i<arr.length;i++)//to call every element once
{
count=1;//a no. exists atleast once
for(int j=i+1;j<arr.length;j++)//counting once again
{
if(arr[i]==arr[j])
{
count++;
}
}
if(count>1)
{
b=arr[i];
}
}
return b;
}
public static int[] takeInput() {
Scanner s = new Scanner(System.in);
int size = s.nextInt();
int arr[] = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = s.nextInt();
}
return arr;
}
public static void main(String[] args) {
int[] arr = takeInput();
System.out.print(duplicate(arr));
}
}