The problem
Write a method that returns a new array by eliminating the duplicate values in the array using the following method header: public static int[] eliminateDuplicates(int[] list)
. Write a test program that reads in ten integers, invokes the method, and displays the result.
Breaking it down
static final int NUMBER_INPUT_USER = 10;
public static void main(String[] args) {
int[] numbers = new int[NUMBER_INPUT_USER];
Scanner input = new Scanner(System.in);
System.out.print("Enter " + NUMBER_INPUT_USER + " numbers: ");
for (int i = 0; i < numbers.length; i++) {
numbers[i] = input.nextInt();
}
input.close();
System.out.println("Your inputs with duplicates removed: ");
Arrays.stream(numbers).distinct().mapToObj(String::valueOf)
.map(i -> i + " ").forEach(System.out::print);
}
Output
Enter 10 numbers: 2
3
3
3
4
5
6
7
7
7
Your inputs with duplicates removed:
2 3 4 5 6 7