Recursive Method Prints 4 Times

后端 未结 4 613
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 04:05

So I am working on learning how to utilize recursion through Java. I have written a simple program that adds all the numbers between 1 and n and it looks to do it\'s job. Wh

4条回答
  •  不知归路
    2021-01-17 04:27

    I've drawn a sequence diagram, hope this can explain the recursion procedure.

    There is a retrospective procedure for recursion, the next command will be pushed into the call stack before the recursion method is called. So we can simply say System.out.println will be pushed to call stack before recursiveCall, then after the recursiveCall returned the main process will continue with the top command on the stack, that is System.out.println.

提交回复
热议问题