Find the factors of an integer

The problem

Write a program that reads an integer and displays all its smallest factors in increasing order. For example, if the input integer is 120, the output should be as follows: 2, 2, 2, 3, 5.

Breaking it down

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    System.out.print("Enter first integer number: ");
    int num = input.nextInt();

    input.close();

    for (int i = 2; i <= num;) {

        if (num % i == 0) {
            System.out.print(i + " ");
            num /= i;
        } else {
            i++;
        }
    }
}

Output

Enter first integer number: 120
2 2 2 3 5