Sir why i am having the run error and what it is?
See my code:
import java.util.Scanner;
public class Main {
static int N,M;
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
N=s.nextInt();
M=s.nextInt();
char maze[][]=new char[1001][1001];
for(int i=0;i<N;i++) {
for(int j=0;j<M;j++) {
maze[i][j]=s.next().charAt(0);
}
}
printpath(maze);
}
public static boolean printpath(char maze[][]) {
int sol[][]=new int[N][M];
if (solvemaze(maze, 0, 0, sol) == false) {
printnegativeSolution();
return false;
}
printSolution(sol);
return true;
}
public static boolean isitsafe(char maze[][],int row,int col) {
return (row>= 0 && row < N && col >= 0 && col < M && maze[row][col] == 'O' );
}
public static boolean solvemaze(char[][] maze,int row,int col,int[][] sol){
if(row==N-1 && col==M-1) {
sol[row][col]=1;
return true;
}
if(isitsafe(maze, row, col)==true) {
sol[row][col]=1;
if(solvemaze(maze, row, col+1,sol)) {
return true;
}
if(solvemaze(maze, row+1, col,sol)) {
return true;
}
sol[row][col]=0;
return false;
}
return false;
}
public static void printSolution(int sol[][])
{
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
System.out.print(sol[i][j]+" ");
System.out.println();
}
}
public static void printnegativeSolution()
{
int a=-1;
System.out.println(a);
}
}