Java-递归
package cn.bruce.file; public class recursion { public static void main(String[] args) { System.out.println(fun(4));// 递归求加法连加 System.out.println(fun1(4));// 递归求乘法连加(阶乘) System.out.println(fun2(5));// 斐波那切数列 } // 递归求加法连加 public static int fun(int a) { if (a == 1) { return 1; } return a + fun(a - 1); } // 递归求乘法连加(阶乘) public static int fun1(int a) { if (a == 1) { return 1; } return a * fun1(a - 1); } // 斐波那切数列 public static int fun2(int a) { if (a == 1) { return 1; }if (a==2) { return 1; } return fun2(a-1) + fun2(a - 2); } }