点击打开链接
1057 N的阶乘
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
输入N求N的阶乘的准确值。
Input
输入N(1 <= N <= 10000)
Output
输出N的阶乘
Input示例
5
Output示例
120
java好~
import java.*;
import java.math.BigInteger;
import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int n = sc.nextInt();
BigInteger sum = BigInteger.ONE;//赋初始值1
for(int i=1;i<=n;i++) {
sum=sum.multiply(BigInteger.valueOf(i));//将i转化成大数再乘
}
System.out.println(sum);
}
}
}