| 12345678910111213141516171819202122232425 |
- package com.lovecoding.day04;
- /**
- * @author WanJl
- * @version 1.0
- * @title Demo10
- * @description 求1!+2!+3!+...+10!的值 阶乘相加
- * 计算 1! + 2! + 3! + ... + 10! 的值并输出。其中 n! = 1×2×3×...×n。
- * 1! 1*1
- * 2! 1*2
- * 3! 1*2*3
- * @create 2026/7/10
- */
- public class Demo09 {
- public static void main(String[] args) {
- int sum=0;//结果 和
- int f=1; //起始值 1
- for (int i = 1; i <=10; i++) {
- f*=i; //乘
- sum+=f; //累加
- }
- System.out.println(sum);
- }
- }
|