このコードをコンパイルしようとすると、else without if というエラーが表示されます。すべてのブレースが適切な場所にあると信じています。添付した写真にある他のエラーも発生しますが、ifエラーなしではelseを使用できないため、それらが存在すると信じています。
問題コード:
public static boolean goNorth(){
boolean success;
if(maze[currCol]currRow - 1] == CLEAR){
maze[currCol][startRow -1] = PATH;
currRow--;
success = goNorth();
if(!success){
success = goWest();
if(!success){
success = goEast();
if(!success){
maze[currCol][currRow] = VISITED;
currRow++;
}
}
}
return success;
} else {
return false;
}
}
public static boolean goWest(){
boolean success;
if(maze[currCol - 1]currRow] == CLEAR){
maze[currCol - 1][startRow] = PATH;
currRow--;
success = goWest();
if(!success){
success = goSouth();
if(!success){
success = goNorth();
if(!success){
maze[currCol][currRow] = VISITED;
currCol++;
}
}
}
return success;
} else {
return false;
}
}
public static boolean goEast(){
boolean success;
if(maze[currCol + 1]currRow] == CLEAR){
maze[currCol + 1][startRow] = PATH;
currRow--;
success = goEast();
if(!success){
success = goNorth();
if(!success){
success = goSouth();
if(!success){
maze[currCol][currRow] = VISITED;
currCol--;
}
}
}
return success;
} else {
return false;
}
}
public static boolean goSouth(){
boolean success;
if(maze[currCol]currRow + 1] == CLEAR){
maze[currCol][startRow + 1] = PATH;
currRow--;
success = goSouth();
if(!success){
success = goEast();
if(!success){
success = goWest();
if(!success){
maze[currCol][currRow] = VISITED;
currRow--;
}
}
}
return success;
} else {
return false;
}
}
エラー: