My question relates to the following code which uses recursion.
1 public class factorial1
2 {
3public static void main(
String[] args)
4{
5 System.out.println( "factorial of 4 is " + factorial(3));
6 }
7static int factorial( int n )
8 {
9 if ( n == 0 )
10 return 1;
11 else
12 return n * factorial( n-1 );
13}
14 }
prints--> factorial of 4 is 24
My question is how do you trace the execution of the program?
When the return statement is reached on line 12 the method factorial is called again. What is the
value of n * factorial( n-1 ) and where is it stored?