递归

来源:互联网 发布:淘宝大促 编辑:程序博客网 时间:2024/06/14 09:44

递归的应用

1.      什么是递归:

方法内部调用方法本身。

例子1:

public classRecursion {

    public static void main(String[] args) {

        test2(100);

    }  

    public static void test2(intn) {

        if(n == 0) {

            return;

        }

        System.out.println(n);

        test2(n- 1);

    }

}

运行结果:

100

99

98

……

3

2

1

0 0