我想知道如何将此代码放入 switch 语句中
我想在 switch 语句中执行此 if else 语句,请帮助我找出如何将此代码更改为 switch 语句。
if (board[r - 1][c] == ' ' && board[r][c - 1] == ' ') {
nextRow = r;
nextCol = c - 1;`enter code here`
return true;
}
// We will try to move the cell up.
if (board[r - 1][c] == ' ') {
nextRow = r - 1;
nextCol = c;
return true;
}
// We will try to move the cell to the right.
else if (board[r][c + 1] == ' ') {
nextRow = r;
nextCol = c + 1;
return true;
}
// We will try to move the cell to the left.
else if (board[r][c - 1] == ' ') {
nextRow = r;
nextCol = c - 1;
return true;
}
// We will try to move the cell down.
else if (board[r + 1][c] == ' ') {
nextRow = r + 1;
nextCol = c;
return true;
}
System.out.println("Error due to Array Bound Index");
return false;
}
慕妹3242003
尚方宝剑之说
DIEA
相关分类