java如何处理语法错误?
我写了一个小程序,但发现了几个错误。我很困惑,不知道为什么以及如何修复它。有人能帮我解释一下错误并找出如何使它工作吗
代码如下:
class Solution {
public int tribonacci(int n) {
SearchQueue searchQueue = new SearchQueue();
return searchQueue.count(n);
}
}
class SearchQueue {
private int theQueue = new int[38];
theQueue[0] = 0;
theQueue[1] = 1;
theQueue[2] = 1;
public int[] count(int n) {
if (n == 0) {
return 0;
}
if (theQueue[n] != null) {
return theQueue[n];
}
for (int i = 0; i < 38; i++) {
theQueue[n] = count(n - 3) + count(n - 2) + count(n - 1);
}
return theQueue[n];
}
}
# 1 楼答案
这不是定义数组的正确方法
应该是
private int[] thequeue = new int[38];
在函数中,还应返回int而不是int[]