我正在创建一个以 1 和 3 作为索引值的数组。我有两个来代表我的边界。我已经编写了四个 for 循环来为我的数组设置边框。除了为右侧创建边框的 for 循环之外,它们似乎都可以工作。
value: 5
222222
213133
231133
211131
231331
222222
//Creates the border indexes for the cells represented by the value 2
for (int top = 0; top < cells.length; top++)
cells[0][top] = 2;
for (int bottom = 0; bottom < cells.length; bottom++)
cells[cells.length-1][bottom] = 2;
for (int left = 0; left < cells.length; left++)
cells[left][0] = 2;
//for some reason, this code doesn't do anything
for (int right = 0; right < cells.length; right++)
cells[right][cells.length] = 2;
// Creates the first generation of cells randomly
for (int i = 1; i <m; i++)
{
for (int j = 1; j < m; j++)
{
double CellCreate = Math.random();
if (CellCreate > .5)
{
cells[i][j] = 1;
}
else
{
cells[i][j] = 3;
}
}
}
//Prints the cells
for (int x = 0; x < cells.length;x++)
{
for (int y = 0; y < cells.length; y++)
{
System.out.print(cells[x][y]);
}
System.out.println();
}