/*
递归求阶乘:
1.定义一个求阶乘的方法
2.注意1的阶乘是1,作为递归的出口
*/
public class Demo {
public static void main(String[] args) {
int num = getJc(5);
System.out.println(num);
}
//1.定义一个求阶乘的方法
public static int getJc(int n){
if(n == 1){
return 1;
}else {
return n * getJc(n-1);
}
}
}
用递归的思想求阶乘
最新推荐文章于 2023-01-01 15:23:34 发布