输入:n
输出:n!
import java.math.BigInteger;
import java.util.Scanner;
public class jiecheng{
public static BigInteger A(int a){
BigInteger temp=new BigInteger("1");
BigInteger sum=new BigInteger("1");
for(int i=1;i<=a;i++){
sum = sum.multiply(temp);
temp=temp.add(new BigInteger("1"));
}
return sum;
}
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int n;
while(true){
n=in.nextInt();
BigInteger res=A(n);
System.out.println("结果是:"+res);
}
}
}
本文介绍了一个使用Java实现的阶乘计算器程序。该程序利用BigInteger类处理大整数运算,通过循环计算并返回指定整数的阶乘结果。用户可以通过控制台输入任意正整数,程序将输出对应的阶乘结果。
12万+

被折叠的 条评论
为什么被折叠?



