递归
来源:互联网 发布:摩卡网络 编辑:程序博客网 时间:2024/06/08 16:48
package 递归;
public class Test {
public static void main(String[] args) {
System.out.println( jiech(5) );
}
//求n的阶乘
public static int jiech(int n){
//1的阶乘是1
if(n == 1){
return 1;
}
//n的阶乘等于n*(n-1的阶乘)
return n*jiech(n-1);
}
}