package com.xuyigang1234.chp01;//1!+2!+3!+....+10!的和public class Demo5 { public static void main(String[] args) { int sum =0; //和初始化值 for(int i=1;i<11;i++) { int jieCheng=1; //阶乘初始化值 for(int j=1;j<=i;j++) { jieCheng*=j; } sum+=jieCheng; } System.out.println("1!+2!+3!+....+10!的和为: "+ sum); }}
输出为:1!+2!+3!+....+10!的和为: 4037913