1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package JieCheng;
import java.util.Scanner; //导入Scanner的包
public class Jiecheng { public static int JieC(int n) //这是求n的阶乘的递归函数 { if(n==1)return 1; return n*JieC(n-1); }
public static void main(String[] args) { // TODO Auto-generated method stub
Scanner s=new Scanner(System.in); int n=s.nextInt(); //输入n
int sum=0; //记录和
for(int i=1;i<=n;i++) { sum+=JieC(i); }
System.out.println(sum); } }
|