斐波那契函数
/* * 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 该图片仅限百度用户交流使用。直接用Javaeye的相册吧。 2 楼 chenhsong 2011-03-21 裴小星 写道该图片仅限百度用户交流使用。
直接用Javaeye的相册吧。
很少用图片的,下次注意了,谢谢! 3 楼 hxz_qlh 2011-08-07 [int fib(int n)
{
int f[2] = {0, 1};
int i = 2;
for(i=2;i<=n;i++) {
f[0] = f[0] + f[1];
f[0] = f[0] + f[1];
f[1] = f[0] - f[1];
f[0] = f[0] - f[1];
}
return f[1];
}/code]