public class Main { public static int fibonacci(int index) { // 设置结束递归的限制条件 if (index == 1 || index == 2) { return 1; } // F(index) = F(index-1) + F(index-2) return fibonacci(index - 1) + fibonacci(index - 2); } public static void main(String[] args) { for(int i=1;i<=10;i++){ System.out.println(fibonacci(i)+" "); } } }
斐波那契递归实现
最新推荐文章于 2024-08-29 18:44:48 发布