2、 编写一程序,计算出1!+2!+3!+…..+15!

用JAVA编程
2024-12-15 20:13:16
推荐回答(1个)
回答1:

import java.math.BigInteger;

public class Test {
public static void main(String[] args) {
int n = 15;
BigInteger value = BigInteger.ONE, last = BigInteger.ONE;
for (int i = 2; i <= n; ++i) {
last = last.multiply(BigInteger.valueOf(i));
value = value.add(last);
}
System.out.println(value);
}

}