1+2!+3!+...n!

package com.cn.hbut.test;


/**
 * @author wickedvalley
 * description://1+2!+3!+...n!
 * date:2016/10/29
 *
 */
public class test1 {
public static void main(String[] args) {
int sum=totalSum(3);
System.out.println(sum);
}
//求n!
public static int getSum(int n){
if(n==1)
return 1;
else
return n*getSum(n-1);
}
//返回n个阶乘的和
public static int totalSum(int n){
int sum=0;
for(int i=1;i<=n;i++){
sum+=getSum(i);
}
return sum;
}
}

你可能感兴趣的:(笔试编程)