package com.csair.rsa; /** * 斐波纳契数列(Fibonacci Sequence) * @author Administrator * @data Mar 23, 2012 */ public class FS { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub for(int n = 1; n < 30; n++){ int result = getFS(n); System.out.println("第"+n+"项的值为:"+result); } } /** * 计算第n项的值 * @param n * @return */ public static int getFS(int n){ int z = 0; if(n == 1){ z = 1; }else if(n == 2){ z = 1; } else{ z = getFS(n-1)+getFS(n-2); } return z; } }
?