package com.zxw.test;
import java.util.ArrayList;
public class Recursion {
/**
* 递归调用2-斐波纳契数列
*
* @param args
*/
static ArrayList lists = new ArrayList();
public static void main(String[] args) {
// long f = f(4);
// System.out.println(f);
long fibonacci = fibonacci(7);
System.out.println(fibonacci);
}
public static long f(int n) {
if (n == 1) {
return 1;
}
return n * f(n - 1);
}
public static long fibonacci(int n) {
if (n == 1 || n == 2) {
return 1;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
递归调用2-斐波纳契数列(java)
于 2024-04-15 11:54:52 首次发布