how to input the character array without giving space between its elements .
and how to report only the rightmost path.
Input of Character array and one desirable solution
Use Buffered reader and use char[] s = in.readLine().toCharArray(); This stores your input character by character in array s
Can you tell what is wrong in my code
yes, please post your code
import java.util.; import java.io.; public class Main { private static boolean flag=false; private static void getPath(char[][] grid,int row,int col, int[][] path){ if(row==grid.length-1 && col==grid[0].length-1){ path[row][col]=1; flag=true; for(int i=0;i<=row;i++){ for(int j=0;j<=col;j++){ System.out.print(path[i][j]); } System.out.println(); } return; } if(row==grid.length || col==grid[0].length || grid[row][col]==‘X’){ return; } path[row][col]=1; getPath(grid,row,col+1,path); if(!flag){ getPath(grid,row+1,col,path); path[row][col]=0; }else return; } public static void main(String[] args) throws IOException { Scanner cin=new Scanner(System.in); InputStreamReader isr=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(isr); int n=cin.nextInt(); int m=cin.nextInt(); if(n>=1 && m>=1 && n<=1000 && m<=1000){ char[][] grid=new char[n][m]; for(int i=0;i<n;i++){ char[] cc=in.readLine().toCharArray(); for(int j=0;j<m;j++){ if(cc[j]==‘X’ || cc[j]==‘O’){ grid[i][j]= cc[j]; } } } getPath(grid,0,0,new int[n][m]); } } }