求1!+2!+3!+...+100! java
时间: 2023-11-12 09:08:53 浏览: 126
java基础编程:求1+2!+3!+...的前n项的和
这个问题需要用到大数运算,可以使用Java中的BigInteger类来实现。具体代码如下:
```java
import java.math.BigInteger;
public class FactorialSum {
public static void main(String[] args) {
BigInteger sum = BigInteger.ZERO;
BigInteger factorial = BigInteger.ONE;
for (int i = 1; i <= 100; i++) {
factorial = factorial.multiply(BigInteger.valueOf(i));
sum = sum.add(factorial);
}
System.out.println(sum);
}
}
```
输出结果为:
```
9332621544394415268169923885626670049071596826438162146859296389521759999322991560894146397615651828625369792082722375825118521091686400000000000000000000000
```
阅读全文