本帖最後由 吳聲寬 於 2021-1-27 13:23 編輯
- import java.util.Scanner;
- public class Ch10
- {
- static int f(int n)
- {
- if(n<2)
- return n;
- else
- return f(n-2)+f(n-1);
- }
- public static void main(String[] args)
- {
- Scanner s=new Scanner(System.in);
- int a;
- System.out.print("Enter your amout: ");
- a=s.nextInt();
- for(int i=0;i<=a;i++)
- System.out.print(f(i)+" ");
- }
- }
複製代碼 |