需要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;
}
}
# 1 楼答案
您将
available[]
定义为一维数组,并将其与二维available[i][j]
一起使用# 2 楼答案
available
是一维数组,因此无法写入available[i][j]
。将其更改为类似smh的available[i]