递归小程序之求阶乘

1、题目描述

  阶乘 n! = n * (n-1) * (n-2) * ...* 1(n>0)

2、代码实现

 1 package com.wcy.october;
 2 
 3 /**
 4  * 时间:2016年10月23日
 5  * 题目:(1)阶乘 n! = n * (n-1) * (n-2) * ...* 1(n>0)
 6  */
 7 public class RecursionTest5 {
 8 
 9     public static int getResult(int n){
10         if (n == 1) {
11             return 1;
12         }else {
13             return getResult(n-1)*n;
14         }
15     }
16     
17     public static void main(String[] args) {
18         int result = getResult(5);
19         System.out.println(result);
20     }
21 }
原文地址:https://www.cnblogs.com/wangchaoyuan/p/5991453.html