java经典算法_020求1+2!+3!+...+20!的和

package wzs.arithmetics;

//题目:求1+2!+3!+...+20!的和 
public class Test_wzs20
{
    public static void main(String[] args)
    {
        long temp = 1;
        long sum = 0;
        for (int i = 1; i <= 20; i++)
        {
            temp = temp * i;
            sum += temp;
        }
        System.out.println("sum=" + sum);
    }
}

输出结果:

sum=2561327494111820313



你可能感兴趣的:(java编程思想,java编程思想,经典算法)