Associate
- Joined
- 2 Nov 2007
- Posts
- 488
Hello,
Im trying to go through some basic Java exercises on arrays, and was wondering if you could give me a point in the right direction.
The question is:
# Add a constructor Matrix(double[][] m) that can store as a 2-D array a matrix with an arbitrary number of rows and columns. The values of the individual elements are of type double.
# Add the methods nCols(), nRows() returning (as an int) the number of columns and rows.
So far i have:
Which Eclipse doesnt like. I think its becuase i havent set the constructor correctly (or at all!) and was wondering if you could give me any help? I uderstand arrays in general, but i dont understand how i am meant to use them as a constructor.
Cheers
Im trying to go through some basic Java exercises on arrays, and was wondering if you could give me a point in the right direction.
The question is:
# Add a constructor Matrix(double[][] m) that can store as a 2-D array a matrix with an arbitrary number of rows and columns. The values of the individual elements are of type double.
# Add the methods nCols(), nRows() returning (as an int) the number of columns and rows.
So far i have:
Code:
// Empty constructor
public Matrix(double[][] m){}
public static int nCols(Matrix m){
return m[0].length;
}
public static int nRows(Matrix m){
return m.length;
}
Which Eclipse doesnt like. I think its becuase i havent set the constructor correctly (or at all!) and was wondering if you could give me any help? I uderstand arrays in general, but i dont understand how i am meant to use them as a constructor.
Cheers
Last edited: