Factorial using Recursion in Java

前端 未结 18 1409
春和景丽
春和景丽 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:02

    To understand it you have to declare the method in the simplest way possible and martynas nailed it on May 6th post:

    int fact(int n) {
        if(n==0) return 1;
        else return n * fact(n-1);
    }
    

    read the above implementation and you will understand.

提交回复
热议问题