java完成fibonacci數列進修示例分享(斐波那契數列)。本站提示廣大學習愛好者:(java完成fibonacci數列進修示例分享(斐波那契數列))文章只能為提供參考,不一定能成為您想要的結果。以下是java完成fibonacci數列進修示例分享(斐波那契數列)正文
輸入:1 1 2 3 5
public class FibonaciTest {
public static void main(String[] args) {
Fibonaci(5);
}
public static void Fibonaci (int count) {
int[] num = new int[count];
num[0] = num[1] = 1;
for (int i = 2; i < count; i++) {
num[i] = num[i - 1] + num[i - 2];
}
for (int j = 0; j < count; j++){
System.out.print(num[j] + " ");
}
}
}