简化 Java 中连续的 “if” 语句
2022-09-03 03:11:50
我有一系列声明,如下所示:if
if (board[x+1][y]==true) {
ar+=1;
}
if (board[x][y+1]==true) {
ar+=1;
}
if (board[x-1][y]==true) {
ar+=1;
}
if (board[x][y-1]==true) {
ar+=1;
}
if (board[x+1][y+1]==true) {
ar+=1;
}
if (board[x+1][y-1]==true) {
ar+=1;
}
if (board[x-1][y+1]==true) {
ar+=1;
}
if (board[x-1][y-1]==true) {
ar+=1;
}
有没有办法用Java简化/压缩这些语句?