java 1.6 递归

递归

分类:

直接递归:称为方法自身调用自己。

间接递归:可以A方法调用B方法,B方法调用C方法,C方法调用A方法。

实例:

``

public class Test018 {
    public static void main( String[] args ) {
        System.out.println(f(5));

    }
public static int f(int n){
        if (n==1){
            return 1;
        }else
        { return n*f(n-1);}
}

}

输出结果:120

posted @ 2022-03-21 22:16  奈落。  阅读(25)  评论(0)    收藏  举报