斐波那契数列:
package array_Study;
import java.util.Scanner;
public class FibonacciRatched {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入你想要的斐波拉契序列的长度:");
int length = scan.nextInt();
iteration(length);
}
//迭代方法
private static void iteration(int length) {
int i;
int a[]=new int [length];
a[0]=0;
a[1]=1;
System.out.printf("%d %d ",a[0],a[1]);
for(i=2;i<a.length;i++){
a[i]=a[i-1]+a[i-2];
System.out.printf("%d ",a[i]);
}
}
}