代码:
public void placeO(int xpos, int ypos) {
for(int i=0; i<3;i++)
for(int j = 0;j<3;j++) {
// The line below does not work. what can I use to replace this?
if(position[i][j]==' ') {
position[i][j]='0';
}
}
}
最佳答案
将其更改为:if(position[i][j] == 0)
每个字符都可以与一个整数进行比较。
默认值为 '\u0000'
,即 0
用于 char 数组元素。
我想这正是您所说的 empty cell
的意思。
要测试它,您可以运行它。
class Test {
public static void main(String[] args) {
char[][] x = new char[3][3];
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
if (x[i][j] == 0){
System.out.println("This char is zero.");
}
}
}
}
}
关于java - 如何检查 char 数组是否有空单元格以便我可以在其中打印 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21502859/