在Java中编写一个计算阶乘的递归方法。不幸的是它不起作用,我怀疑这是因为我不太确定的2个参数 - 我用星号包围了。那些属于那里的正确参数吗?或者我是否需要将它们更改为其他内容以及为什么?
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***);
}
答案 0 :(得分:2)
此代码无法编译。
public int fact...
代替public fact...
fact(int n)
而不是fact(n)