What is wrong in my code?

package backtracking;

import java.util.Scanner;

public class ratinamaze {

public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	int n = scn.nextInt();
	int m = scn.nextInt();
	char[][] maze = new char[n][m];
	for (int i = 0; i < n; i++) {

		for (int j = 0; j < m; j++) {
			maze[i][j] = scn.next().charAt(0);;
		}

	}
	int [][] ans=new int[maze.length][maze[0].length];
	if (ratinmaze(maze, 0, 0, ans, new boolean[maze.length][maze[0].length])) {
		display(ans, n-1, m-1);
	}else {
		System.out.println(-1);
	}
}
public static void display(int [][] ans,int n,int m) {
	for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            System.out.print(ans[i][j] + " ");
        }
        System.out.println();
    }
	
}

public static boolean ratinmaze(char[][] maze, int row, int col, int [][] ans, boolean[][] visited) {
	if (row==maze.length-1 && col==maze[0].length-1) {
		ans[row][col]=1;
		return true;
	}
	if (row==maze.length ||col==maze.length || maze[row][col]=='X' ||visited[row][col]==true) {
		return false;
	}
	visited[row][col]=true;
	ans[row][col]=1;
	ratinmaze(maze,row,col+1,ans,visited);
	ratinmaze(maze,row+1,col,ans,visited);
	visited[row][col]=false;
	ans[row][col]=0;
	return false;

}

}

hey @harsh.hj
1st changes input format
char[][] maze = new char[n][m];
for (int i = 0; i < n; i++) {
String str = scn.next();
for (int j = 0; j < m; j++) {
maze[i][j] = str.charAt(j);
;
}
}
2. if (row==maze.length ||col==maze[0].length || maze[row][col]==‘X’ ||visited[row][col]==true) {
return false;
}

instead of if (row==maze.length ||col==maze.length || maze[row][col]==‘X’ ||visited[row][col]==true) {
return false;
}
3. Find the rightmost path
correct code :

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int m = scn.nextInt();
char[][] maze = new char[n][m];
for (int i = 0; i < n; i++) {
String str = scn.next();
for (int j = 0; j < m; j++) {
maze[i][j] = str.charAt(j);
;
}
}
int[][] ans = new int[maze.length][maze[0].length];
if (ratinmaze(maze, 0, 0, ans, new boolean[maze.length][maze[0].length])) {
display(ans, n - 1, m - 1);
} else {
System.out.println(-1);
}
}

public static void display(int[][] ans, int n, int m) {
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			System.out.print(ans[i][j] + " ");
		}
		System.out.println();
	}
}

public static boolean ratinmaze(char[][] maze, int row, int col, int[][] ans, boolean[][] visited) {
	if (row == maze.length - 1 && col == maze[0].length - 1) {
		ans[row][col] = 1;
		return true;
	}
	if (row >= maze.length || col >= maze[0].length || maze[row][col] == 'X' || visited[row][col] == true) {
		return false;
	}
	boolean a =false, b=false;
	visited[row][col] = true;
	ans[row][col] = 1;
	a= ratinmaze(maze, row, col + 1, ans, visited);
	if(a) {
		return a;
	}
	b= ratinmaze(maze, row + 1, col, ans, visited);
	if(b) {
		return b;
	}
	visited[row][col] = false;
	ans[row][col] = 0;
	return false;
}

}

why you have puted a ,b =recursive call ???

@harsh.hj
We need to print
rightmost path

can u plz elaborate that why we are using a,b for finding rightmost path

a= ratinmaze(maze, row, col + 1, ans, visited);
here a is true ,No need to check further
because rightmost path follow krkte hue end tk reach kr gaye ,
my fun is return type boolean
answer store krke rkhna hoga
a= ratinmaze(maze, row, col + 1, ans, visited);
b= ratinmaze(maze, row + 1, col, ans, visited);

visited[row][col] = false;
ans[row][col] = 0;
return a|| b; 

it is print all possible path

ok sir thanks for resolving my doubt