Java计算Fibonacci(斐波那契)序列的前n项
输入
16
输出
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
import java.util.*;
public class app4_5 {
public static void main(String[] args) {
int i = 0, j = 1, k = 1;
int n;
Scanner read=new Scanner(System.in);
System.out.println("请输入要输出前第几项:");
n =read.nextInt();
while (k <= n) {
System.out.print(" " + i + " " + j);
i = i + j;
j = i + j;
k = k + 2;
}
System.out.println();
}
}