I'm having trouble with recursion in java. So I have the following method and i should transform it only with recursion without any loop.
public static List<Integer> primesLoop(int n) {
List<Integer> factors = new ArrayList<Integer>();
int f = 2;
while (f <= n)
if (n % f == 0) {
factors.add(f);
n /= f;
} else
f++;
return factors;
}
The recursive method should start with the same form:
public static List<Integer> primesRec(int n);
and also I should define help methods for the transformation The result is for example:
primesRec(900) -> prime factors of 900 : [2, 2, 3, 3, 5, 5]