求阶乘和(二次递归)
作者:互联网
1 public class test72 { 2 /** 3 * 求阶乘和 4 * @param args 5 */ 6 public static void main(String[] args) { 7 int sum = fac2(4); 8 System.out.println(sum); 9 } 10 11 public static Integer fac1(int n) { 12 if(n == 1) { 13 return 1; 14 } 15 return n * fac1(n - 1); 16 } 17 public static Integer fac2(int n) { 18 int sum = 0; 19 for (int i = 1; i <= n; i ++) { 20 sum += fac1(i); 21 } 22 return sum; 23 } 24 }
标签:递归,二次,int,sum,fac2,static,阶乘,public 来源: https://www.cnblogs.com/Leafbud/p/12782229.html