标签:递归
递归:自己调用自己,归去归来,一定要有结束条件。
递归的深度不能太深,不然 就会有栈溢出,也不要进行发散递归
package day13;
public class Demo01 {
public static void main(String[] args) {
int n = 5000;
int y = f(n);
System.out.println(y);
}
public static int f(int n) {
if (n == 1)
return 1;
return n + f(n - 1);
}
}本文出自 “浪漫的偷笑” 博客,请务必保留此出处http://lmdtx.blog.51cto.com/6942028/1699835
标签:递归
原文地址:http://lmdtx.blog.51cto.com/6942028/1699835