Recursion 2
From Huben's Wiki
(Created page with "Review Handout 2. Java keeps track of which methods are running and have called each other on the '''stack'''. When there is a run-time error in a program, Dr. Java shows you t...") |
|||
Line 22: | Line 22: | ||
return 1; | return 1; | ||
} | } | ||
− | System.out.println("Recursing with | + | System.out.println("Recursing with factorial(" + (n - 1) +") now"); |
int result = factorial(n - 1, stackLevel + 1); | int result = factorial(n - 1, stackLevel + 1); | ||
− | System.out.print("Resuming Stack Level: " + stackLevel + ". Result received from | + | System.out.print("Resuming Stack Level: " + stackLevel + ". Result received from factorial(" + (n - 1) +"): " + result); |
System.out.println(" Multiplying result by " + n + " and returning " + n * result); | System.out.println(" Multiplying result by " + n + " and returning " + n * result); | ||
return n * result; | return n * result; |