Here is the maze traversal method and full code
import java.io.*;
import java.util.*;
public class Quest {
    static char[][] maze = new char[10][10];
    public static void main(String[] args) throws IOException {
       Scanner scan = new Scanner(new File("quest.dat"));
       String s = "";
       int n = scan.nextInt();
       scan.nextLine();
       while (n-->0) {
          for (int i=0; i<10; i++) {
            s = scan.nextLine();
            if (s.equals("-"))
              break;
          for (int j=0; j<10; j++)
            maze[i][j] = s.charAt(j);
       }
       int r = searchR();
       int c = searchC();
       //System.out.println(r + " " + c);
       mazeTraverse(r, c);
       for (int i=0; i<10; i++) {
         for (int j=0; j<10; j++)
           System.out.print(maze[i][j]);
         System.out.println();
     }
   }
}
public static void mazeTraverse(int r, int c) {
if ((r>0 && r<maze.length && c>0 && c<maze.length) && maze[r][c] == 'H')
  return;
if ((r>0 && r<maze.length && c>0 && c<maze.length) && (maze[r][c]=='.' || maze[r][c]=='A')) {
  if (!(maze[r][c]=='A'))
    maze[r][c] = 'O';
        mazeTraverse(r+1, c);
        mazeTraverse(r-1, c);
        mazeTraverse(r, c+1);
        mazeTraverse(r, c-1);
        maze[r][c] = '.';
   }
}
public static int searchR() {
for (int r=0; r<10; r++) {
  for (int c=0; c<10; c++) {
    if (maze[r][c]=='A')
      return r;
  }
}
return -1;
}
public static int searchC() {
   for (int r=0; r<10; r++) {
     for (int c=0; c<10; c++) {
       if (maze[r][c]=='A')
         return c;
     }
   }
   return -1;
   }
}
When I run the program it just continuously runs and doesn't stop, but I checked and I am getting the correct r and c values so what could be the problem? The mazes are 10x10 so they are perfect squares.
 
    