返回列表 發帖
  1. import java.util.Scanner;


  2. public class Ch71234 {
  3.         static int ff(int a)
  4.         {
  5.                 if(a<2)
  6.                         return a;
  7.                 else
  8.                         return ff(a-2)+ff(a-1);
  9.         }

  10.         public static void main(String[] args) {
  11.                 int a;
  12.                 Scanner s=new Scanner(System.in);
  13.                 System.out.println("推算第幾項費氏數列: ");
  14.                 a=s.nextInt();
  15.                 for(int i=0; i<=a; i++)
  16.                 {
  17.                         System.out.print(ff(i)+" ");
  18.                 }

  19.         }

  20. }
複製代碼

TOP

返回列表