The simplest way to implement a matrix is to use an array of arrays as shown in Program . In this case, we use three fields. The first two fields, numberOfRows and numberOfColumns record the dimensions of the matrix. The third field, array, is a Java array of arrays of doubles.
Program: DenseMatrix fields and constructor.
The constructor takes two arguments, m and n, and constructs the corresponding matrix. Clearly, the running time of the constructor is O(mn). (Remember, Java initializes all the array elements to zero).