Factorial using Recursion in Java

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

    public class Factorial {
    public static void main(String[] args) {
       int n = 7;
       int result = 1;
       for (int i = 1; i <= n; i++) {
           result = result * i;
       }
       System.out.println("The factorial of 7 is " + result);
    }
    }
    

提交回复
热议问题