Print distinct numbers

The problem

Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers.

Breaking it down

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    System.out.print("Enter ten numbers: ");

    Set<Integer> numbers = new HashSet<Integer>();
    for (int i = 0; i < 10; i++) {
        int num = input.nextInt();
        numbers.add(num);
    }

    input.close();

    System.out.print("The distinct numbers are: ");
    numbers.stream().forEach(i -> {
        System.out.println(i + " ");
    });
}

Output

Enter ten numbers: 10
10
9
2
3
3
4
4
4
4
The distinct numbers are: 2
3
4
9
10