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
I have two problems with the code above: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; }
1)Is there a way to 'count' the number of arguments this method has? As opposed to writing '2' in, I think that would be better if it was something likeCode:for(int i = 0; i < 2; i++)2)Well, I can see that the matrix M above will beCode:for(int i = 0; i < 'number of arguments in this method'; i++)
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.




Reply With Quote
