當前位置:編程學習大全網 - 電腦編程 - 裴波那切系列的前20個數(1.1.2.3.5.8.13.21.34.75....)每輸出5行換壹個。。。用Java求的

裴波那切系列的前20個數(1.1.2.3.5.8.13.21.34.75....)每輸出5行換壹個。。。用Java求的

呵呵。剛學的我也只能夠幫助妳這些啦:

public class Fbnc {

public static void main(String[] args) {

int f[]=new int[20];

f[0]=f[1]=1;

for(int i=0;i<18;i++){

f[i+2]=f[i]+f[i+1];

}

for(int i=0;i<20;i++){

if(i%5==0){

System.out.println();

}

System.out.print(f[i]+" ");

}

}

}

運行結果:

1 1 2 3 5

8 13 21 34 55

89 144 233 377 610

987 1597 2584 4181 6765

  • 上一篇:編程如何制作障礙代碼
  • 下一篇:如何用vhdl按壹個鍵改變壹個狀態,松開後狀態不變,再按壹次恢復原來的狀態?
  • copyright 2024編程學習大全網