[英]Define border around 2D array - Java
I have an array: 我有一个数组:
Cell[][] cells = new Cell[width+2][height+2];
Which is filled according to a certain input: 根据特定输入填充:
for (int i = 1; i < cells.length-1; i++) {
for (int j = 1; j < cells[i].length-1; j++) {
if (certain input) {
cells[i][j] = new Cell(true);
} else {
cells[i][j] = new Cell(false);
}
}
}
Now I still need to define the border cells which need to become false. 现在,我仍然需要定义需要变为假的边界单元。 I tried this with another for loop but somehow this does not seem to work.
我尝试了另一个for循环,但是以某种方式似乎不起作用。 Any help is appreciated!
任何帮助表示赞赏!
Don't know if I understand you, but if you want to make a frame for the true cells you should do something like: 不知道我是否了解您,但是如果您想为真正的单元格做一个框架,则应该执行以下操作:
for (int i = 0; i < cells.length; i++) {
for (int j = 0; j < cells[i].length; j++) {
if (i== 0 || i == cells.length-1 || j== 0 || j == cells.length-1) {
cells[i][j] = new Cell(false);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.