日期:2014-05-20 浏览次数:20652 次
import java.util.concurrent.*;
public class Fibonacci implements Runnable{
private int n = 0;
private int[] fibo;
public Fibonacci(){}
public Fibonacci(int n){
this.n = n;
fibo = new int[n];
}
public String toString(){
String str = "";
for(int i = 0;i < n; i ++){
str += fibo[i] + " ";
}
return str;
}
public void run(){
fibo[0] = 0;
fibo[1] = 1;
n -= 2;
int i = 2;
while(n-- > 0){
fibo[i] = fibo[i - 1] + fibo [i - 2];
i ++;
}
System.out.println(toString());
Thread.yield();
}
public static void main(String[] arg){
ExecutorService exec = Executors.newCachedThreadPool();
for(int i = 0;i < 5;i ++)
exec.execute(new Fibonacci(20));
exec.shutdown();
}
}