返回列表 發帖
本帖最後由 吳聲寬 於 2021-1-27 13:23 編輯
  1. import java.util.Scanner;
  2. public class Ch10
  3. {
  4.         static int f(int n)
  5.         {
  6.                 if(n<2)
  7.                         return n;
  8.                 else
  9.                         return f(n-2)+f(n-1);
  10.         }
  11.         public static void main(String[] args)
  12.         {
  13.                 Scanner s=new Scanner(System.in);
  14.                 int a;
  15.                 System.out.print("Enter your amout: ");
  16.                 a=s.nextInt();
  17.                 for(int i=0;i<=a;i++)
  18.                         System.out.print(f(i)+" ");
  19.         }
  20. }
複製代碼

TOP

返回列表