Stack Overflow error occurs when using recursive fibonacci function

后端 未结 3 1415
Happy的楠姐
Happy的楠姐 2020-12-21 11:12

Here\'s my code and it runs well with values of 400 to 4000 but once it\'s about 4mil, I get stack overflow errors.

Thanks in advance!

public class F         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 11:38

    You can increase the stack size of Java programs. Example:

    java -Xss4m YourProgram
    

    Reference

    Nevertheless I would also recommend an iterative method.

提交回复
热议问题