public static int foo(int i){
if(i==1){
return 1;
}else{
int num= i*foo(i-1);
return num;
}
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int math=scanner.nextInt();
System.out.println(foo(math));
}
关于递归求n的阶乘的写法
最新推荐文章于 2024-09-11 17:43:19 发布