-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoveDuplicates.java
49 lines (37 loc) · 1.19 KB
/
RemoveDuplicates.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package removeduplicates;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author daniel
*/
public class RemoveDuplicates {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Size: ");
int size = input.nextInt();
String[] array = new String[size];
System.out.println("Enter the values of the array, please: ");
for (int i = 0; i < size; i++) {
array[i] = input.next();
}
// System.out.print("Duplicates: ");
// boolean noDuplicates = false;
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
if (array[i].equals(array[j])) {
array[j] = array[size - 1];
size--; j--;
}
}
}
String[] array2 = Arrays.copyOf(array, size);
System.out.print("New Array: " + Arrays.toString(array2));
System.out.println();
}
}