Factorial using Recursion in Java

前端 未结 18 1449
春和景丽
春和景丽 2020-11-27 13:43

I am learning Java using the book Java: The Complete Reference. Currently I am working on the topic Recursion.

Please Note: There are similar questi

18条回答
  •  野性不改
    2020-11-27 14:09

    What happens is that the recursive call itself results in further recursive behaviour. If you were to write it out you get:

     fact(4)
     fact(3) * 4;
     (fact(2) * 3) * 4;
     ((fact(1) * 2) * 3) * 4;
     ((1 * 2) * 3) * 4;
    

提交回复
热议问题