public class Five_factorial { public static void main(String[] args) { /** * 1.普通方法实现5的阶乘 */ int f = 1; for (int i = 5; i >= 1; i--) { f *= i; } System.out.println(f); /** * 2.运用递归实现5的阶乘 */ int n = 5; Five_factorial five_factorial = new Five_factorial(); factorial fa = five_factorial.new factorial(); System.out.println(fa.fact(n)); } class factorial { int fact(int n) { int value = 0; if (n == 1) { value = 1; } else { value = n * fact(n - 1); } return value; } } }