Alright, what I need to do is take a regular matrix of any size, and expand that to whatever size given. My header is as follows:
public int[][] expand(int[][] m, int factor){
where m is the original matrix and factor is the factor to which the matrix is increased, heres an example of what I'm talking about:
723
486
when factor = 3, turns into
777222333
777222333
777222333
444888666
444888666
444888666
Here's the code I wrote so far:
int expandMatrix[][] = new int[m.length*factor][m[0].length*factor];
int d = 0, a = 0;
for(int x = 0; x < m.length ; x++){
for(int y = 0; y < m[0].length; y++){
for(int z = 0; z < factor; z++){
expandMatrix[x][d] = m[x][y];
System.out.println(expandMatrix[x][d]);
d++;
}
for(int z = 1; z < factor; z++){
expandMatrix[z] = expandMatrix[0];
}
}
d = 0;
}
return expandMatrix;
}
But for the 2nd z for statement, it obviously doesn't work due to hard-coded values. The 2nd for loop is my main problem. Anyone with any suggestions?
public int[][] expand(int[][] m, int factor){
where m is the original matrix and factor is the factor to which the matrix is increased, heres an example of what I'm talking about:
723
486
when factor = 3, turns into
777222333
777222333
777222333
444888666
444888666
444888666
Here's the code I wrote so far:
int expandMatrix[][] = new int[m.length*factor][m[0].length*factor];
int d = 0, a = 0;
for(int x = 0; x < m.length ; x++){
for(int y = 0; y < m[0].length; y++){
for(int z = 0; z < factor; z++){
expandMatrix[x][d] = m[x][y];
System.out.println(expandMatrix[x][d]);
d++;
}
for(int z = 1; z < factor; z++){
expandMatrix[z] = expandMatrix[0];
}
}
d = 0;
}
return expandMatrix;
}
But for the 2nd z for statement, it obviously doesn't work due to hard-coded values. The 2nd for loop is my main problem. Anyone with any suggestions?