题目:我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
思路:利用Java的BigInteger能很方便的解决此类问题
import java.math.BigInteger;
import java.util.Scanner;
public class JieCheng {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
BigInteger count=new BigInteger("1");
for (int i = 1; i <= n; i++) {
String str=Integer.toString(i);
BigInteger temp=new BigInteger(str);
count=count.multiply(temp);
}
System.out.println(count);
in.close();
// TODO Auto-generated method stub
}
}