递归阶乘

|--代码

package com.collection;

public class Demo2 {
	public static void main(String[] args) {
		/**
		 * 求5的阶乘
		 */
		//方案1:普通循环
		int i = 1;
		for(int x = 1; x <= 5; x++)
		{
			i= i*x;
		}
		//System.out.println(i);
		
		//方案2:递归
		System.out.println(jc(5));
	}
	public static int jc(int i) {
		if(i==1)
			return 1;
		else
			return i*jc(i-1);
	}
}

流程分析图



版权声明:本文博主原创文章。博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/bhlsheji/p/4881291.html