利用递归求n的阶乘
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.print("请输入您要求的阶乘:");
Scanner scanner = new Scanner(System.in);
int i=scanner.nextInt();
System.out.println(i+"的阶乘为:"+f(i));
}
public static int f(int n) {
if (n == 1) {
return n;
} else {
return n*f(n-1);
}
}
}