0

The error mark pops up when creating the two dimensional array inside the read() method . "matrix[row][col];" . i cant understand wht i am doing wrong.

import java.util.Scanner;
    public class Matrix {
        int row,col,matrix[][];
        Matrix()
        {

        }
        Matrix(int r,int c)
        {
            row = r;
            col = c;

        }
        void read()
        {
            Scanner scan = new Scanner(System.in);
            matrix[row][col];
            int i,j;
            for(i=0;i<row;i++)
            {
                for(j=0;j<col;j++)
                {
                    System.out.println("Enter value: ");
                    matrix[i][j] = scan.nextInt();
                }
            }


        }

    }

1 Answers1

0

The problem is that

matrix[row][col];

is not a statement but an expression. You would instead have to write

 matrix = new int[row][col];

hope it helps, Alex