很简单的Java递归算法

import java.io.*;

public class DiGui {
public static void main(String args[]) {
String s;
try {
System.out.println("Please intput a Number");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
s = br.readLine();
int i = Integer.parseInt(s);
System.out.println(new DiGui().Factorial(i));// 这里调用阶乘递归方法
} catch (IOException e) {
}
}

//下面是一个递归方法. 这是一个阶乘算法的递归.

double Factorial(int n) {
if (n == 1)
return 1;
else
return n * Factorial(n - 1);//调用方法本身. 进行递归.
}
}

原文地址:https://www.cnblogs.com/wuhuisheng/p/1788751.html