- package text369;
- import java.util.Scanner;
- public class text45 {
- static int io(int n)
- {
- if(n<2)
- return n;
- else
- return io(n-2)+io(n-1);
- }
- public static void main(String[] args) {
- System.out.print("請問要推算費氏數列到第幾項次?");
- Scanner s=new Scanner(System.in);
- int a=s.nextInt();
- System.out.println(io(a));
- for(int i=1;i<=a;i++)
- {
- System.out.print(io(i)+"\t");
- }
-
-
-
- }
- }
複製代碼 |