-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveDuplicates.java
More file actions
44 lines (35 loc) · 887 Bytes
/
Copy pathremoveDuplicates.java
File metadata and controls
44 lines (35 loc) · 887 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
package JavaCoding;
import java.util.*;
class Main
{
static int removeDuplicates(int arr[], int a)
{
if (a==0 || a==1)
return a;
int[] temp = new int[a];
int q = 0;
for (int p=0; p<a-1; p++)
if (arr[p] != arr[p+1])
temp[q++] = arr[p];
temp[q++] = arr[a-1];
for (int p=0; p<q; p++)
arr[p] = temp[p];
return q;
}
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array");
int [] arr=new int[10];
for(int i=0;i<arr.length;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("Entered array is ="+Arrays.toString(arr));
Arrays.sort(arr);
System.out.println("Sorted Array is = "+Arrays.toString(arr));
int a = arr.length;
a = removeDuplicates(arr, a);
System.out.print("Unique Array Length= "+a);
}
}