Because I am constantly busy working on something, I have never had time to actually put everything in words and pictures. But, since you got here, then you must have already seen some part of my work - and this is the way I’m talking.I'm 23, born in Romania, student at UPG Romania in software development field. I started from 0, mostly with basic stuff, and I’m evolving every day to an expert. I'm focused on freelancing projects, from small websites, to really heavy stuff. I know that I look and act differently from most developers, but this is why you will love to work with me!

Thursday, March 18, 2010

Copy a matrix of integers into an array


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: