bob bob - 1 year ago 94
Java Question

Basic recursive method - factorial

I am practicing recursion and I can't see why this method does not seem to work.
Any ideas?

public void fact()
{
fact(5);
}

public int fact(int n)
{
if(n == 1){
return 1;
}
return n * (fact(n-1));
}
}


Thanks

Answer Source

Your code seems to work but you are not doing anything with the returned value, put method call fact or fact(5) inside of a System.out.println and see what you get.