有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

需要java数组,但找到整数

我试图比较两个不同数组中的两个值,但最终得到了“Array required but Integer find”编译时错误。我真的无法解决这个问题。我已经标出了错误发生的地方。如果有人能帮我解决这个问题,那将是非常值得的。这是代码

public class Banker
{

    int proccess, n, allocated[][], need[][], maximum[][], available[], safe[];
    boolean done[];

    public Banker(int n, int proccess) {
        this.n = n;
        this.proccess = proccess;
        allocated = new int[n][n];
        need = new int[n][n];
        maximum = new int[n][n];
        safe = new int[proccess];
        done = new boolean[proccess];
    }

    public void getSafeSequence() {
        int result = 0;
        for (int i = 0; i < proccess; ++i) {
            result = getLocation();
            if (result != -1) {
                safe[i] = result;
                done[result] = true;
            } else {
                System.out.println(" No Safe Sequence Exist ");
                break;
            }
        }
        if (result != -1)
            DisplaySequene();
    }

    public int getLocation() {
        boolean flag = true;
        for (int i = 0; i < proccess; ++i) {
            if (done[i] != true) {
                flag = true;
                for (int j = 0; j < n; ++j)
                    ***if (available[i][j] < need[i][j])*** {
                        flag = false;
                        break;
                    }
            }
            if (flag)
                return i;
        }
        return -1;
    }
}

共 (2) 个答案

  1. # 1 楼答案

    您将available[]定义为一维数组,并将其与二维available[i][j]一起使用

  2. # 2 楼答案

    available是一维数组,因此无法写入available[i][j]。将其更改为类似smh的available[i]