
The below method copies an matrix of integers into an array of integers. You must pass to the method: the matrix (y), the number of lines(n) and columns(m) to be copied. The method returns the desired array.
public int[] copyMatrixIntoArray(int[][] y, int n, int m) {
int[] x = new int[n * m];
int i = 0;
int j = 0;
int p = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
x[p] = y[i][j];
p = p + 1;
}
}
return x;
}
No comments:
Post a Comment