The output was correct but it keeps on displaying `-1` at the end of the factors from time to time (infinite looping). I know there's something wrong with the `while` loop inside the recursion method but I don't know what it is. How can I stop the recursive call after getting the final answer? What should I use instead of a `while` loop?

```
public static void main() {
    int num;
    System.out.print("\fInput:");
    num = kb.nextInt();
    int temp = 1;
    factors(num, temp);
}

public static void factors(int num, int temp) {
    int count = 2;

    while (temp != num) {
        if ((num % count) == 0) {
            System.out.print(count + " * ");
            factors(num / count, temp * count);
        } else
            count++;
    }
}

```