jav编写程序求1!+2!+...+10!。
时间: 2023-11-09 12:01:52 浏览: 160
求数字阶乘之和(1!+2!+3!+...+10!)
以下是 Java 代码实现:
```
public class FactorialSum {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += factorial(i);
}
System.out.println("1!+2!+...+10! = " + sum);
}
public static int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
}
```
输出结果为:1!+2!+...+10! = 4037913
阅读全文