案例:计算1!+2!+3!+......+n!

/*
 * 1!+2!+3!+......+n!
 * */
import java.util.Scanner;

public class ForTest{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in );
        System.out.println("请输入N的值:");
        int n = sc.nextInt();
        int sum = 0;
        for(int j = 1; j<=n; j++){
            int num = 1;
            for(int i = 1; i <= j; i++){
                num *= i;
            }
            sum += num;
            }
        System.out.println("各项阶层的和为:" + sum);
    }
}

 

posted @ 2016-11-13 15:34  cheney-yang  阅读(500)  评论(0编辑  收藏  举报