Java中的Fibonacci系列程序使用递归。
以下是必需的程序。
示例
public class Tester {
static int n1 = 0, n2 = 1, n3 = 0;
static void fibbonacci(int count) {
if (count > 0) {
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" " + n3);
fibbonacci(count - 1);
}
}
public static void main(String args[]) {
int count = 5;
System.out.print(n1 + " " + n2);
fibbonacci(count - 2);
}
}输出结果
0 1 1 2 3
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志