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


  2. public class Ch11 {
  3.        
  4.         static int  f(int b)
  5.         {
  6.                 if(b<2)
  7.                 {
  8.                return b;
  9.                
  10.                 }else
  11.                 {
  12.                         return f(b-1)+f(b-2);
  13.                                        
  14.                 }
  15.         }

  16.         public static void main(String[] args) {
  17.                
  18.                 Scanner s=new Scanner(System.in);
  19.                 int b;
  20.                 System.out.println("幾次費氏數列");
  21.                 b=s.nextInt();
  22.                 System.out.println(b+"次費氏數列為"+f(b));
  23.                
  24.                
  25.       

  26.         }

  27. }
複製代碼

TOP

返回列表