我是Java新手,我正努力学习最好的东西。我正在尝试运行此代码,但遇到了错误。
代码:
public class Fibonacci
{
public static void main(String[] args)
{
int[] numbers;
numbers[0]=0;
numbers[1]=1;
numbers = newint[20];
System.out.println("\nFibonacci series:\n");
System.out.println(numbers[0]);
for (int i =2; i<2; i++)
{
numbers[i]=numbers[i-2]+numbers[i-1];
System.out.println( numbers[i] );
}
}
}
错误:
Fibonacci.java:10: error: cannot find symbol
numbers = newint[20];
^
symbol: variable newint
location: class Fibonacci
1 error
答案 0 :(得分:2)
您在ExecutorService executor_ = Executors.newFixedThreadPool(numOfThreads);
for (int i = 0; i < num; ++i) {
executor_.submit(new LongRunningWorker(jobQueue));
}
运算符后缺少空格。此外,您需要在>>为其分配值之前初始化数组,而不是在:
new
答案 1 :(得分:0)
就像在评论中已经说过的那样,更改数组声明,并将循环的上限调整为20:
public static void main(String[] args) {
int[] numbers = new int[20];
numbers[0]=0;
numbers[1]=1;
System.out.println("\nFibonacci series:\n");
System.out.println(numbers[0]);
for (int i = 2; i< 20; i++) {
numbers[i]=numbers[i-2]+numbers[i-1];
System.out.println( numbers[i] );
}
}