今天舍友去面试回来后告诉了我一些面试题,我才发现,我还有好多没学。 在此记录一下
斐波那契数列
public static void main(String
[] args
) {
FBNQL_Array();
}
public static void FBNQL_Array() {
int num1
= 0;
int num2
= 1;
int num3
;
for (int i
= 0; i
< 10; i
++) {
num3
= num1
+ num2
;
System
.out
.print(num3
+" , ");
num1
= num2
;
num2
= num3
;
}
}
斐波那契数列 打印结果是: 1 ,2 , 3 , 5 ,8 ,13 ,21 , 34 , 55 , 89 自身的值会是前两个值的和。