永发信息网

n!的值。要求:n的值在程序中给出,用递归方法解决;显示结果。用java编写

答案:3  悬赏:70  手机版
解决时间 2021-12-21 16:12
  • 提问者网友:太高姿态
  • 2021-12-20 20:32
n!的值。要求:n的值在程序中给出,用递归方法解决;显示结果。用java编写
最佳答案
  • 五星知识达人网友:冷風如刀
  • 2022-01-22 05:07
import java.util.*;

public class Factor {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

int n = input.nextInt();
System.out.print(factor(n));

}

public static int factor(int number){
if(number<1)return 1;
return number*factor(number-1);
}

}
全部回答
  • 1楼网友:英雄的欲望
  • 2022-01-22 05:53
public class Recursion { int result=1; public int nRecursion(int n) { if (n > 0) { result = result * n; nRecursion(n-1); } return result; } }
  • 2楼网友:北方的南先生
  • 2022-01-22 05:34

protected int fun(int n)

{

if(n>0)

{

if(n==1)

return 1;

else return n*fun(n-1);

}

}

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯