forked from krimanisha/Hacktoberfest21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_duplicate.java
More file actions
49 lines (36 loc) · 1.27 KB
/
remove_duplicate.java
File metadata and controls
49 lines (36 loc) · 1.27 KB
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
import java.util.Arrays;
public class remove_duplicate{
static void unique_array(int[] my_array)
{
System.out.println("Original Array : \n");
for (int i = 0; i < my_array.length; i++)
{
System.out.print(my_array[i]+"\t");
}
int no_unique_elements = my_array.length;
for (int i = 0; i < no_unique_elements; i++)
{
for (int j = i+1; j < no_unique_elements; j++)
{
if(my_array[i] == my_array[j])
{
my_array[j] = my_array[no_unique_elements-1];
no_unique_elements--;
j--;
}
}
}
int[] array1 = Arrays.copyOf(my_array, no_unique_elements);
System.out.println("\n ");
System.out.println("\n Array with unique values : \n ");
for (int i = 0; i < array1.length; i++)
{
System.out.print(array1[i]+"\t");
}
System.out.println();
}
public static void main(String[] args)
{
unique_array(new int[] {0, 3, 5, 5, -2, 4, 3, 2});
}
}