java:File类(递归)

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_24644517/article/details/84034643

递归的弊端:

不能调用次数过多,容易导致栈内存溢出

递归的好处:

不用知道循环次数,

实例代码:

public class Demo8_DiGui {

	public static void main(String[] args) {
		System.out.println(fun(9999999));

	}
	
	
	public static int fun(int num) {
		if(num==1) {
			return 1;
		}else {
			return num*fun(num-1); 
		}
		
	}

}

栈内存溢出错误:

正常使用:

猜你喜欢

转载自blog.csdn.net/qq_24644517/article/details/84034643
今日推荐