Java编程练习2——求1!+2!+3!+...+10!的和

版权声明:此账号的博客均为原创,侵权必究! https://blog.csdn.net/qq_37084904/article/details/83146933

1.思路讲解:

分别求出1!,2!,3!...10!的值,然后再相加求值;

求阶乘可以用for循环,然后用a*=b这种形式罗列出来即可;

package Hello;

public class test {

	public static void main(String[] args) {
		int a=1,b=1;
		for(int i=1;i<=10;i++){
			a*=i;
			b+=a;
			System.out.println(i+"!="+a);
		}
		System.out.println("1!+2!+3!+...+10!的和为:"+b);
	}
}

结果为:

猜你喜欢

转载自blog.csdn.net/qq_37084904/article/details/83146933