Demo09.java 577 B

12345678910111213141516171819202122232425
  1. package com.lovecoding.day04;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Demo10
  6. * @description 求1!+2!+3!+...+10!的值 阶乘相加
  7. * 计算 1! + 2! + 3! + ... + 10! 的值并输出。其中 n! = 1×2×3×...×n。
  8. * 1! 1*1
  9. * 2! 1*2
  10. * 3! 1*2*3
  11. * @create 2026/7/10
  12. */
  13. public class Demo09 {
  14. public static void main(String[] args) {
  15. int sum=0;//结果 和
  16. int f=1; //起始值 1
  17. for (int i = 1; i <=10; i++) {
  18. f*=i; //乘
  19. sum+=f; //累加
  20. }
  21. System.out.println(sum);
  22. }
  23. }