1 public class Fibonacci { 2 3 private static int getFibo(int i) { 4 if (i == 1 || i == 2) 5 return 1; 6 else 7 return getFibo(i - 1) + getFibo(i - 2); 8 } 9 10 public static void main(String[] args) { 11 System.out.println("斐波那契数列的前20项为:"); 12 for (int j = 1; j <= 20; j++) { 13 System.out.print(getFibo(j) + " "); 14 if (j % 5 == 0) { 15 System.out.println(); 16 } 17 } 18 } 19 }