一道Java程序问题~

来源:百度知道 编辑:UC知道 时间:2024/06/04 19:41:50
这个Java问题出自thinking in java 4~

Following the form of generics/Fibonacci.java, create a task that
produces a sequence of n Fibonacci numbers, where n is provided to the constructor of the
task. Create a number of these tasks and drive them using threads.

//: generics/Fibonacci.java
// Generate a Fibonacci sequence.
import net.mindview.util.*;
public class Fibonacci implements Generator<Integer> {
private int count = 0;
public Integer next() { return fib(count++); }
private int fib(int n) {
if(n < 2) return 1;
return fib(n-2) + fib(n-1);
}
public static void main(String[] args) {
Fibonacci gen = new Fibonacci();
for(int i = 0; i < 18; i++)
System.out.print(gen.next() + " ");
}
}
我的意思是请大家写一个程序出来~以上的是thinking in java 里的一道习题题目.........

题目主要是 要熟悉 线程的 调度与启动。

Task / Thread.

通过检测count 值 ,可以体会到线程的作用。

递归生成斐波那契数列...呃..有什么问题么..

没问题啊。上面那位说对了,斐波那契

什么问题