title: Recursive Maze in Java
body: <p>I have written a short Java code for solving a simple maze problem to go from S to G.</p>
  
  <p>I do not understand where the problem is going wrong.</p>
  
  <pre><code> import java.util.Scanner;
  
   public class tester
    {
  static char [][] grid={
          {'.','.'},
          {'.','.'},
          {'S','G'},
  };
  
  static int a=2;
  static int b=2;
  
  
  static boolean findpath(int x, int y)
  {
       if((x &gt; grid.length-1) || (y &gt; grid[0].length-1) || (x &lt; 0 || y &lt; 0))
          {
              return false;
          }
       else if(x==a &amp;&amp; y==b){
          return true;
      }
  
       else if (findpath(x,y-1) == true){
          return true;
      }
       else if (findpath(x+1,y) == true){
          return true;
      }
       else if (findpath(x,y+1) == true) {
      return true;
  }
       else if (findpath(x-1,y) == true){ 
      return true;
  }
  return false;
  
  }
  
  public static void main(String[] args){
      boolean result=findpath(2,0);
      System.out.print(result);
      }
  </code></pre>
  
  <p>}</p>
  
  <p>I am giving the starting position directly and goal is defined in a &amp; b. Do help.</p>