在這裏我做了一個代碼,但單個數組,但現在我想將其轉換爲雙數組[] []。如何將單個數組轉換爲雙數組
有些事情應該改變,但我可以得到它的工作。
這是獲得我想要更改爲雙數組的單個數組的類的一部分。
public House[][] neighbors(House victim) {
House[][] n = new House[8];
int row = victim.address/size;
int col = victim.address % size;
if (row != 0 && row != (size - 1) && col != 0 && col != (size - 1)) {
n[0] = houses[victim.address - 1];
n[1] = houses[victim.address + 1];
n[2] = houses[victim.address - size];
n[3] = houses[victim.address - size - 1];
n[4] = houses[victim.address - size + 1];
n[5] = houses[victim.address + size];
n[6] = houses[victim.address + size - 1];
n[7] = houses[victim.address + size + 1];
return n;
}
if (row == 0 && col != 0 && col != (size - 1)) {
n[0] = houses[victim.address - 1];
n[1] = houses[victim.address + 1];
n[2] = houses[victim.address + size];
n[3] = houses[victim.address + size - 1];
n[4] = houses[victim.address + size + 1];
n[5] = houses[victim.address + (size * (size - 1))];
n[6] = houses[victim.address + (size * (size - 1)) + 1];
n[7] = houses[victim.address + (size * (size - 1)) - 1];
return n;
}
if (row == (size - 1) && col != 0 && col != (size - 1)) {
n[0] = houses[victim.address - 1];
n[1] = houses[victim.address + 1];
n[2] = houses[victim.address - (size * (size - 1))];
n[3] = houses[victim.address - (size * (size - 1)) + 1];
n[4] = houses[victim.address - (size * (size - 1)) - 1];
n[5] = houses[victim.address - size];
n[6] = houses[victim.address - size - 1];
n[7] = houses[victim.address - size + 1];
return n;
}
if (col == 0) {
n[0] = houses[victim.address + (size - 1)];
n[1] = houses[victim.address + 1];
n[2] = houses[victim.address - size];
n[3] = houses[victim.address - size - 1];
n[4] = houses[victim.address - size + 1];
n[5] = houses[victim.address - (size * (size - 1))];
n[6] = houses[victim.address - (size * (size - 1)) + 1];
n[7] = houses[victim.address - (size * (size - 1)) - 1];
return n;
}
什麼是「大小」? – ray