首页 > 其他 > 详细

递归小程序之求阶乘

时间:2016-10-24 01:45:22      阅读:243      评论:0      收藏:0      [点我收藏+]

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 }

 

递归小程序之求阶乘

原文:http://www.cnblogs.com/wangchaoyuan/p/5991453.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!