试写出求递归函数F(n)的递归算法,并消除递归 F(n) = n+1 当n=0 F(n) = nF

2025-06-22 22:24:20
推荐回答(1个)
回答1:

public int f(int n) throws Exception {
   if(n<0) throw new Exception("参数n不能小于零");
   if(n==0) return n+1 ;
   return n*f(n/2) ;
}
 Java写了个方法,你看行不?