小编Kha*_*mov的帖子

递归计算ln(n!)的java方法

如何实现java方法来ln(n!)递归计算?

这是我的解决方案。我知道这是错误的,但这是迄今为止我想到的唯一解决方案。

double func(int n) {
   double result;
   if(n == 1)
     return 1;
   result = func(n-1) * n;
   return Math.log(result);
}
Run Code Online (Sandbox Code Playgroud)

这是函数返回的内容:

func(2) = 0.6931471805599453  (correct)
func(3) = 0.7320993680864453  (should be: 1.79175946922805500081)
func(4) = 1.0744553356380115  (should be: 3.17805383034794561964)
Run Code Online (Sandbox Code Playgroud)

java algorithm math recursion

0
推荐指数
1
解决办法
943
查看次数

标签 统计

algorithm ×1

java ×1

math ×1

recursion ×1