斐波纳契数列(话说 递归算法真的好慢) import java.util.Scanner; /** * @author 小明 * 注释掉的是递归算法 */ public class FibonacciRow { public static void main(String[] args) { int y; Scanner scan = new Scanner(System.in); y = scan.nextInt(); f(y); // System.out.println(f(y)); } public static long f(int y){ // if(n == 1 || n == 2){ // return 1; // }else{ // return f(n - 1) + f(n - 2); // } long f1 = 1L; long f2 = 1L; long f = 1L; System.out.println("第1个数是:" + f); if(y > 1){ System.out.println("第2个数是:" + f); for(int i = 0; i < y - 2; i++){ f = f1 + f2; System.out.println("第"+ (i + 3) +"个数是:" + f); f1 = f2; f2 = f; } } return f; } }