package 大整数求三十项和;
// 使用BigInteger类计算1!+3!+5!+。。。。。。的前30项的和
import java.math.*;
public class sum
{
public static void main(String args[]) {
BigInteger sum = new BigInteger("0");
int i = 30;//三十项
Integer j = 1;//当前项
while (0 < i--) {
sum = sum.add(factorial(new BigInteger(j.toString())));
j += 2;
}
System.out.println(sum);
}
public static BigInteger factorial(BigInteger bint) {
if (bint.equals(BigInteger.ZERO) || bint.equals(BigInteger.ONE)) {
return BigInteger.ONE;
}
return bint.multiply(factorial(bint.subtract(BigInteger.ONE)));
}
}
// 使用BigInteger类计算1!+3!+5!+。。。。。。的前30项的和
import java.math.*;
public class sum
{
public static void main(String args[]) {
BigInteger sum = new BigInteger("0");
int i = 30;//三十项
Integer j = 1;//当前项
while (0 < i--) {
sum = sum.add(factorial(new BigInteger(j.toString())));
j += 2;
}
System.out.println(sum);
}
public static BigInteger factorial(BigInteger bint) {
if (bint.equals(BigInteger.ZERO) || bint.equals(BigInteger.ONE)) {
return BigInteger.ONE;
}
return bint.multiply(factorial(bint.subtract(BigInteger.ONE)));
}
}