say I have two int arrays of length 3 (ex: a = [ 1 2 3] and b = [4 5 6])
I would like a method that returns the 2x3 Matrix:
M =
1 2 3
4 5 6.
I have tried using
Code:
public int[][] createMatrix(int[] a, int[] b){
double[][] M = new double[2][a.length];
for(int i = 0; i < 2; i++){
for (int j = 0; j <a.length; j++){
M[i][j] = a[j];
}
}
return M;
}
I have two problems with the code above:
1)Is there a way to 'count' the number of arguments this method has? As opposed to writing '2' in
Code:
for(int i = 0; i < 2; i++)
, I think that would be better if it was something like
Code:
for(int i = 0; i < 'number of arguments in this method'; i++)
2)Well, I can see that the matrix M above will be
123
123
for the simple reason that I have not used the array b anywhere in the code. I am not sure how I can incorporate b in the inner loop.
Any help is appreciated.