用Java进行大数处理(BigInteger)-hdu1042

时间:2023-03-09 04:40:36
用Java进行大数处理(BigInteger)-hdu1042

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042

题目描述:

用Java进行大数处理(BigInteger)-hdu1042

代码实现:

 import java.util.Scanner;
import java.math.BigInteger;
public class Main{ public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
while(cin.hasNext())//等价于!=EOF
{
int n = cin.nextInt();
BigInteger p = BigInteger.ONE;//相当于C语言中的给p赋值为0
for(int i=1;i<=n;i++)
{
p=p.multiply(BigInteger.valueOf(i));//Java中大数相乘用的是multiply();不能直接相乘
}
System.out.println(p);
}
cin.close();
} }

相关文章