【发布时间】:2016-02-06 23:58:08
【问题描述】:
所以,我正在尝试制作一个包含名为 Nodes 的对象的板,但由于某种原因,当我尝试创建 Nodes 数组时,我在标题中收到错误,但不明白为什么。根据我所学到的一切,
“公共静态节点[][]板=新节点[11][11];”
应该是一个有效的陈述。我在这里要做的就是制作一个 11x11 的数组。我稍后在循环中填充数组。
我在这里和其他地方寻求帮助,但找不到任何解决问题的方法。有些想法很接近,但问题仍然存在。任何帮助都会很棒。
public class Board {
//creates the board
public static Node[][] board = new Node[11][11];
//create an empty node and place it in every other location
//like a checkered board.
for(int i = 0; i < board.length; i++) {
for (int j = 0; j< board[i].length; j+=2) {
if(i%2 == 0) {//if it is an even row start at 0
board[i][j] = new Node(null);
}else if(j+1 < board[i].length){//if odd row and less than length, start at 1
board[i][j+1] = new Node(false);
}else{
}
}
}
}
【问题讨论】:
-
如果这是 Java,您可以添加
java标签。 -
您得到的确切错误是什么?是否抛出异常?
-
你的代码编译不出来这么难说你有什么问题
-
我忘了把它放在方法或构造函数中
标签: java arrays loops multidimensional-array 2d