我有一个 if 语句在 Java 中抛出“无效的赋值运算符”(在两行上)。我无法弄清楚我在这里做错了什么。任何帮助表示赞赏:
if ((row >= 0) && (row < this.rows) && ((col – 1) >= 0) && ((col – 1) < this.cols)) {
nbrNeighbors += grid[row][col – 1];
}
我有一个 if 语句在 Java 中抛出“无效的赋值运算符”(在两行上)。我无法弄清楚我在这里做错了什么。任何帮助表示赞赏:
if ((row >= 0) && (row < this.rows) && ((col – 1) >= 0) && ((col – 1) < this.cols)) {
nbrNeighbors += grid[row][col – 1];
}
看起来您在减号运算中使用了错误的字符:– ('EN DASH' (U+2013))。尝试使用 - 代替。
我已经在我的 IDE 中检查了您的示例,唯一对我来说似乎错误的是您的减号(-)字符:
Illegal character (U+2013)。
尝试粘贴我的版本:
if ((row >= 0) && (row < this.rows) && ((col - 1) >= 0) && ((col - 1) < this.cols)) {
nbrNeighbors += grid[row][col - 1];
}