import java.util.Scanner; /** * 递归求阶乘 * */ public class Demo { public static void main(String[] args) { System.out.println("请输入一个整数:"); Scanner s = new Scanner(System.in); int n = s.nextInt(); Demo tfr = new Demo(); System.out.println(n + "! = " + tfr.recursion(n)); } public long recursion(int n) { long value = 0; if (n == 1 || n == 0) { value = 1; } else if (n > 1) { value = n * recursion(n - 1); } return value; } }