0

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]);
        }
3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by stultuske
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.