public class TestMethod3 { |
public static void main(String[] args) { |
//第二种方式:递归 |
System.out.println(getFibo( 16 )); |
} |
|
//算出第n项对应的数 |
public static int getFibo( int n){ |
if (n== 2 ){ |
return 1 ; |
} |
if (n== 1 ){ |
return 0 ; |
} |
return getFibo(n- 1 )+getFibo(n- 2 ); |
} |
|
|
} |