JAVA--自制斐波那契数列输出
生活随笔
收集整理的這篇文章主要介紹了
JAVA--自制斐波那契数列输出
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
累了,寫點(diǎn)簡單的。
1 public class hello { 2 3 /** 4 * @param args 5 */ 6 public static void main(String[] args) { 7 int Fabnum = 10; 8 int sum = 0; 9 System.out.print("Serial:\t"); 10 for(int i = 1; i <= Fabnum; i++) 11 { 12 System.out.print(i + "\t"); 13 } 14 System.out.println(); 15 System.out.print("Fabnum:\t"); 16 for(int i = 1; i <= Fabnum; i++) 17 { 18 System.out.print(Fab(i) + "\t"); 19 } 20 } 21 static int Fab(int i) 22 { 23 int result; 24 if (i == 1 || i == 2){ 25 result = 1; 26 }else{ 27 result = Fab(i-1) + Fab(i - 2); 28 } 29 30 return result; 31 } 32 33 }轉(zhuǎn)載于:https://www.cnblogs.com/aguncn/archive/2013/04/27/3048035.html
總結(jié)
以上是生活随笔為你收集整理的JAVA--自制斐波那契数列输出的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 获取url特定参数
- 下一篇: [AT2567] [arc074_c]