/** */ /** * FactorialOfSum.java * 求1到20的阶乘之和 * @author CodingMouse * @version 0.1 2008-4-26 */ public class FactorialOfSum ... { public static void main(String[] args) ...{ //保存当前数与上一个数阶乘的乘积结果 long sum = 1; //保存并累加每一次阶乘结果 long total = 0; //循环20次作为阶乘因子 for (int i = 1 ; i <= 20 ; i++) ...{ //保存计算结果 sum *= i; total += sum; } System.out.println("1到20的阶乘之和为:" + total); }}