### java

#### If statement concerning matrix cell not returning true(java)

```I have a project for a class that is to solve a maze(matrix), which is simple enough, however i'm having some trouble with an if statement that should validate the usability of the matrix cell, to see if that number is a part of the path.
Here's the test Maze I've created:
// 0 = start
// 1 = path
// 2 = wall
// 3 = end
// 5 = tried
// 6 = final path
int [][] maze = {{2,2,2,0,2,2,2,2,2,2},
{2,2,2,1,2,2,1,1,1,2},
{2,2,2,1,2,2,2,2,1,2},
{2,2,2,1,2,2,2,1,1,2},
{2,2,1,1,2,2,1,2,1,1},
{2,1,1,0,2,2,2,2,2,2},
{2,1,2,0,2,2,2,2,2,2},
{2,1,1,0,2,2,2,2,2,2},
{2,2,3,0,2,2,2,2,2,2},};
And here is the method to check if the current cell is valid to walk on:
private boolean valid (int row, int column) {
boolean result = false;
// checks if cell is inside of the matrix
if (row >= 0 && row < maze.length &&
column >= 0 && column < maze.length) {
// checks if cell is not blocked, if it has previously been tried or it's the end
if (maze[row][column] == 1 || maze[row][column] == 3 || maze[row][column] == 0 || maze[row][column] == 5) {
result = true;
}else{
result = false;
}
}
return result;
}
From using print statements I've seen that the problem maybe in the nested if statement. But there might be another problem I am not sure of, which is on the solving method.
public boolean solve(int row, int column ) {
boolean solved = false;
if (valid(row, column)) {
maze[row][column] = 5;
if (maze[row][column] == 1 || maze[row][column] == 0){
if( !solved){//it's going to call the function it self and move if possible.
solved = solve(row + 1, column); // South
if (!solved)
solved = solve(row, column + 1); // East
if (!solved)
solved = solve(row - 1, column); // North
if (!solved)
solved = solve(row, column - 1); // West
}
if (solved) // part of the final path
maze[row][column] = 7;
}else if (maze[row][column] == 3) {
solved = true;
System.out.println("lol the end");
}
//exception here not to leave the maze and case there's no 0
}
return solved;
}
```
```Put the statement
maze[row][column] = 5;
just after the next (if) statement:
if (maze[row][column] == 1 || maze[row][column] == 0){
as it protect to correctly evaluate the condition in this if statement.```

Encrypt Message

code
soft
python
ios
c
html
jquery
cloud
mobile