So for example, this is what I'm asking: how can you convert this:
{{0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{9, 0, 1}}
to this:
{{0, 1, 2},
{0, 1, 2},
{0, 1, 2},
{0, 1, 2}}
This is what I have so far:
void fillDown(int[][] grid) {
int[][] m = {{}};
int[][] newArray = zero(m);
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[0].length; j++) {
if(j== m.length-1){
print(newArray[i][j]);
}else{
print(newArray[i][j] + " ");
}
}
}
}
int[][] zero(int[][] m) {
int rows = m.length;
int columns = m[0].length;
int[][] tempArray = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
tempArray[i][j] = m[i][j];
}
}
return tempArray;
}
But, when I input some values, it doesn't work as expected
For example, when I input something like:
{{0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{9, 0, 1}}
it will still return what I inputed:
{{0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{9, 0, 1}}
How would I do this?
for(int i = 0; i < array.length; i++){ for(int j = 0; j < array[0].length; j++){array[i][j] = i;}}