返回列表 發帖
  1. import java.util.Scanner;
  2. public class ch54
  3. {
  4.       public static void main(String args[])
  5.       {
  6.            int x;
  7.            Scanner ss=new Scanner(System.in);
  8.            System.out.println("請問你要推算費氏數列的哪一個項次?");
  9.            x=ss.nextInt();
  10.            System.out.println("費氏數列的"+x+"項次的值為"+nr(x));
  11.       }
  12.       public static int nr (int h)
  13.       {
  14.            if(h<=1)
  15.            return h;
  16.            else
  17.            return nr(h-1)+nr(h-2);
  18.       }
  19. }
複製代碼

TOP

返回列表