打印斐波那契數

 

package com.jerry.ch04;

public class PrintFibonacci {

	public static void main(String[] args) {
		for (int i=0; i<10; i++) {
			System.out.print(fib(i) + " ");
		}
		
	}
	
	static int fib(int n) {
		if (n<2) {
			return 1;
		} else {
			return fib(n-1) + fib(n-2);
		}
	}

}
相關文章
相關標籤/搜索