返回列表 發帖
  1. package text369;
  2. import java.util.Scanner;
  3. public class text45 {
  4.         static int io(int n)
  5.         {
  6.                 if(n<2)
  7.                         return n;
  8.                 else
  9.                         return io(n-2)+io(n-1);
  10.         }
  11.         public static void main(String[] args) {
  12.                 System.out.print("請問要推算費氏數列到第幾項次?");
  13.                 Scanner s=new Scanner(System.in);
  14.                 int a=s.nextInt();
  15.                 System.out.println(io(a));
  16.                 for(int i=1;i<=a;i++)
  17.                 {
  18.                         System.out.print(io(i)+"\t");
  19.                 }
  20.                
  21.                
  22.                
  23.         }

  24. }
複製代碼
張閎鈞OuO

TOP

返回列表