java用for循环求 s=1!+ 2!+ 3!+ …+10!的值
时间: 2023-11-21 09:58:56 浏览: 125
求s=a+aa+aaa+aaaa+aa...a的值.docx
5星 · 资源好评率100%
以下是Java使用for循环求s=1!+2!+3!+...+10!的值的代码:
```java
public class FactorialSum {
public static void main(String[] args) {
int sum = 0; int factorial = 1;
for (int i = 1; i <= 10; i++) {
factorial *= i;
sum += factorial;
}
System.out.println("1!+2!+3!+...+10!的阶乘和是:" + sum);
}
}
```
运行结果为:1!+2!+3!+...+10!的阶乘和是:4037913
阅读全文