这个就是个简单的递归过程,具体看看怎么来实现:
package excise;
public class Test2 {
public static void main(String args[]){
for(int j=1;j<31;j++){
System.out.println("前面"+j+"的阶乘累加值为"+sumAll(20));
}
}
public static long func(int m){
long value=0;
if(m==0||m==1){
value=1L;
}else{
value=m*func(m-1);
}
return value;
}
public static long sumAll(int n){
long temp=0;
for(int i=1;i<=n;i++){
temp=temp+func(i);
}
return temp;
}
}