题目:求1+2!+3!+...+20!的和
public class Recursion {
public static void main(String args[]) throws NumberFormatException, IOException{
System.out.println("请输入一个数");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num1=Integer.parseInt(br.readLine());
int value=getRecursion(num1);
System.out.println(num1+"的阶乘是"+value);
int result1=getAdd(num1);
System.out.println("结果是"+result1);
} public static int getRecursion(int num){
if(num==1){
return 1;
}
else{
return num*getRecursion((num-1));
}
}
public static int getAdd(int res){
int result=0;
for(int i=1;i<=res;i++){
result+=getRecursion(i);
}
return result;
}
}