基本算法思想----递归

递归算法计算阶乘

import java.util.Scanner;
public class DiGui {
	static long fact(int n)
	{
		if(n<=1)
			return 1;
		else
			return n*fact(n-1);
	}
	public static void main(String[] args){
		int i;
		System.out.print("请输入要求阶乘的一个整数:");
		Scanner input = new Scanner(System.in);
		i = input.nextInt();
		System.out.print(i+"的阶乘结果为:"+fact(i));
	}
}

  

posted on 2015-04-29 15:44  Mathematics  阅读(247)  评论(0编辑  收藏  举报