import java.util.Scanner;
public class Jiecheng {
public static int jiecheng(int n) {
//int k=1;
//while(n!=0) {
// k*=n;
// n--;
//}
//return k;
if(n==1) {
return n=1;
}else {
return n*jiecheng(n-1);
}
}
public static void main(String[] args) {
Scanner sca=new Scanner(System.in);
System.out.println("请输入一个正整数:");
int n=sca.nextInt();
System.out.println(n+"的阶乘是: "+jiecheng(n));
}
}
原文:https://www.cnblogs.com/wangdachui-luoruhua/p/12386020.html