Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 语法错误怎么办?_Java_Algorithm - Fatal编程技术网

Java 语法错误怎么办?

Java 语法错误怎么办?,java,algorithm,Java,Algorithm,我写了一个小程序,但发现了几个错误。我很困惑,不知道为什么以及如何修复它。有人能帮我解释一下错误并找出如何使它工作吗 代码如下: 这不是定义数组的正确方法 应该是 private int[]thequeue=new int[38] 在函数中,还应返回int而不是int[] class Solution { public int tribonacci(int n) { SearchQueue searchQueue = new SearchQueue();

我写了一个小程序,但发现了几个错误。我很困惑,不知道为什么以及如何修复它。有人能帮我解释一下错误并找出如何使它工作吗

代码如下:


这不是定义数组的正确方法

应该是

private int[]thequeue=new int[38]

在函数中,还应返回int而不是int[]


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];
    }
}