CS2
Recursion
8
Order is IMPORTANT!
n
public long factorial(int n) {
n
return n*factorial(n-1);
n
if (n == 0) {
n
return 1;
n
}
n
}
n
You must put the base case
before
the recursive
n
part of the definition or bad things will happen –
in this case a stack overflow will result!