java编写应用程序,求1!+2!+…+20!。
时间: 2023-11-13 16:54:30 浏览: 61
以下是Java代码实现1!+2!+…+20!的求和:
```
public class FactorialSum {
public static void main(String[] args) {
long sum = 0;
for (int i = 1; i <= 20; i++) {
long factorial = 1;
for (int j = 1; j <= i; j++) {
factorial *= j;
}
sum += factorial;
}
System.out.println("1!+2!+...+20! = " + sum);
}
}
```
输出结果为:1!+2!+...+20! = 2561327494111820313
阅读全文