用BigInteger算1到100的阶乘和

public static void main(String[] args) {
	//1到100的阶乘和
	BigInteger bi = new BigInteger("1");
	BigInteger sum = new BigInteger("0");
	for(int i=1;i<=100;i++) {
		for(int j=1;j<=i;j++) {
			bi=bi.multiply(new BigInteger(j+""));//算阶乘   把j转换成字符串类型
		}
		sum=sum.add(bi);
		bi=bi.valueOf(1);  //重置bi
	}
	System.out.println(sum);
}

你可能感兴趣的:(用BigInteger算1到100的阶乘和)