Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
1 2 3
Sample Output
1 2 6
此题主要是解决在a.multiply(i)再mulitply()中不能够用整形,必须是大整形所以可以改为multiply(new BigInteger(""+i) );
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
static BigInteger[] ans;//注意定义大数的数组的放法再BigInteger后边加上数组的符号[].
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
//BigInteger i;
int i,n;
ans=new BigInteger[10010];
ans[0]=BigInteger.valueOf(1);
ans[1]=BigInteger.valueOf(1);
ans[2]=BigInteger.valueOf(2);
for(i=3;i<=10001;i++)
{
ans[i]=ans[i-1].multiply(new BigInteger(""+i) );
}
while(cin.hasNext())
{
n=cin.nextInt();
System.out.println(ans[n]);
}
}
}
2万+

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



