What is wrong with this code. when it do system.out.println(matrix[0][0] i should get 1 char i get the entire line.

int r =Integer.parseInt(line.substring(0));
            int c = 10;
            String[][] matrix = new String[r][c];
            
        while (line !=null)
        {
            for(int i =0; i< r; i++)
            {
             
                for (int j =0; j< c; j++)
                {
                    line = br.readLine();
                    matrix[i][j] = line;
                }
            }
        }
        
            System.out.print(matrix[0][1]);
        }

Well, go figure:

line = br.readLine();
matrix[i][j] = line;

If you put the whole line in there, that's what you're going to get.

so what function can i use to read in a single char at a time?

read the line, and within the loop, you just extract a single char from that line.
that's the one you put in your array, next loop, you read the next char and so on, till you've reached the end of the line

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.