其他分享
首页 > 其他分享> > 求1!+2!+...+20!的和并显示,同时输出结果

求1!+2!+...+20!的和并显示,同时输出结果

作者:互联网

package chapter_after5;

public class Five_4 {
	public static void main(String[] args) {
		int num = 20;
		double mult, sum = 0;
		for (int i = 1; i <= num; i ++) {
			mult = 1;
			for (int j = 1; j <= i; j++) {
				mult *= j;
			}
			System.out.println( i + "的阶乘为:" + mult);
			sum += mult;
		}
		System.out.println("所有阶乘的和为" + sum);
	}
}

标签:输出,20,int,sum,System,阶乘,+...+,mult,out
来源: https://blog.csdn.net/weixin_42082663/article/details/120694206