返回列表 發帖
  1. import java.util.Scanner;
  2. public class.ch54
  3. {
  4.   public static void main(Sting args[])
  5.   {
  6.     int x;
  7.     Scanner s=new Scanner(System.in);
  8.     System.out.print("請問想推算的費式數列的是第幾項次");
  9.     x=s.nextInt();
  10.     System.out.println("費式數列的第"+x+"項,值為:"+fib(x));
  11.    
  12.   }public static int fib(int n)
  13.   {
  14.     if(n<=1)
  15.         return n;
  16.     else
  17.         return fib(n-1)+fib(n-2);
  18.   }
  19. }
複製代碼

TOP

返回列表