public static void main (String[] args)
{
System.out.println(factorial(5));
}
public int factorial(int n)
{
if(n <= 1){
return 1;
}
else{
Are you asking how recursion works internally? The one sentence answer is that every thread has a "call stack" and every time a method is called, a new entry gets pushed onto this stack, which has information about which method is called, and what the arguments were. When the method is finished it places its return value back on the same stack and the calling method pulls it off. So at its height your stack will look like
factorial (1) called by factorial (2) called by factorial (3) called by factorial (4) called by factorial (5)
The Wikipedia article on call stacks seems pretty thorough at first glance.