代码实现:求1+2!+3!+...+20!的和

//求1+2!+3!+...+20!的和 
public class Test21 {
	public static void main(String[] args) {
		long sum = 1;
		long sum2 = 0;
		for (int i = 2; i <= 4; i++) {
			for (int j = 2; j <= i; j++) {
				sum = sum * j;
				System.out.println(sum);
			}
			sum2 =sum2 +sum ;
			sum = 1;
		}
		System.out.println(sum2);
	}
}

 

posted on 2017-03-09 19:54  LoaderMan  阅读(707)  评论(0编辑  收藏  举报

导航