//计算前1+3!+5!+..前30项和
//274410818470142134209703780940313
import java.math.*;
public class p126_5{
public static void main(String[] args){
BigInteger sum=new BigInteger("0"),
xiang=new BigInteger("1"),
one=new BigInteger("1"),
two=new BigInteger("2"),
i=one,a=one,
m=new BigInteger("30");
while(i.compareTo(m)<=0){
xiang=xiang.multiply(i);
i=i.add(one);
a=i.remainder(two);
if(a.compareTo(two)==0){
break;
}
else{
sum=sum.add(xiang);
}
}
System.out.println(sum);
}
}
java程序设计基础教程第二版: p126_5 等差数列求和
最新推荐文章于 2024-05-15 10:17:33 发布