递归的弊端:

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

递归的好处:

不用知道循环次数,

实例代码:

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); 
		}
		
	}

}

栈内存溢出错误:

java:File类(递归)

正常使用:

java:File类(递归)

相关文章:

  • 2021-12-19
  • 2021-06-23
  • 2021-09-05
  • 2022-01-12
  • 2021-06-22
  • 2021-09-26
  • 2021-07-08
猜你喜欢
  • 2021-10-17
  • 2022-02-07
  • 2021-12-25
  • 2022-12-23
  • 2021-12-16
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案