今天舍友去面試回來後告訴了我一些面試題,我才發現,我還有好多沒學。
在此記錄一下
斐波那契數列
public static void main(String[] args) {
FBNQL_Array();
}
/**
* @Description: 斐波那契數列
* @Author: Y_sj
* @Date: 2019/11/1
*/
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
自身的值會是前兩個值的和。