斐波那契函数
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package Test;import java.util.Scanner;/** * * @author Jasper */public class Fibonacci { public static void main(String[] args) { System.out.println("Please input the n:"); Scanner keyboard = new Scanner(System.in); long n = keyboard.nextLong(); while(n>0) { System.out.print(funFib(n)+"\t"); n--; } } public static long funFib(long n) { if(n==0||n==1) return n; else return funFib(n-1)+funFib(n-2); }}
?
1 楼 裴小星 2011-03-21 该图片仅限百度用户交流使用。