Code:
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)
每个 char 都可以与 int 进行比较。
默认值为'\u0000'
i.e. 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.");
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)