-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveDuplicates.java
More file actions
30 lines (30 loc) · 918 Bytes
/
RemoveDuplicates.java
File metadata and controls
30 lines (30 loc) · 918 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
import java.util.Scanner;
import java.util.Arrays;
public class RemoveDuplicates {
public static int arrayLength(int[] arr){
int length=0;
for(int i : arr){
length++;
}
return length;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements you want in array : ");
int size = sc.nextInt();
int[] arr = new int[size];
System.out.print("Enter the elements of array one with spaces: ");
for (int i = 0; i < size; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
for (int i = 0; i < size - 1; i++) {
if (arr[i] != arr[i + 1]) {
System.out.printf("%d ", arr[i]);
i++;
}
}
System.out.printf("%d", arr[size - 1]);
sc.close();
}
}