Friday, 13 September 2013

Recursive method in Java that calculates factorials not working

Recursive method in Java that calculates factorials not working

Coding a recursive method in Java that calculates factorials.
Unfortunately it's not working, and I suspect it's because of the 2
parameters that I wasn't too sure about -- which I surrounded with
asterisks. Are those the correct parameters that belong there? Or do I
need to change them to something else and why? Thanks in advance!
public fact(n)
{
return this.factHelp(n, ***n+1*** );
}
private factHelp(n, result)
{
if (n == 0)
return result;
else
return this.factHelp(n – 1, ***result***);
}

No comments:

Post a Comment