一,循环的方式计算
public static void main (String[] args) throws java.lang.Exception { int z=0,j=0,temp=0; for(int i=0;i<20;i++){ if(i==0||i==1){ z=1; j=1; System.out.print(z+","); }else{ temp=z+j; z=j; j=temp; System.out.print(temp+","); } } }二,递归的方式实现:
public static void main (String[] args) throws java.lang.Exception { for(int i=0;i<18;i++){ System.out.print(change(i)+","); } } private static int change(int i){ if(i==0||i==1){ return 1; } return change(i-1)+change(i-2); }