package himi.hebao04; import java.math.BigDecimal; public class TestDemo07 { public static void main(String[] args) {
// TODO 自动生成的方法存根 BigDecimal sum = new BigDecimal(0.0);
BigDecimal factor = new BigDecimal(1.0);
int i=1;
while( i<=20) {
sum = sum.add(factor);
++i;
factor = factor.multiply(new BigDecimal(1.0/i));
}
System.out.println("阶乘的结果是:"+sum);
} }