# Double the size of a 2d

• 01-20-2011, 06:19 AM
smokinjoachim
Double the size of a 2d
I am trying to double the size of a array. My code is below, it is now working when it prints it is just printing zeros, it is isn't copying the values. Any help would be greatly appreciated.

public static int [][] double2D(int [][]twoD)
{
//int [][] superArray = twoD.length*2;
int [][] superArray = new int[1][1];
for(int i = 0; i < twoD.length; i++)
{
for(int j = 0; j < twoD[i].length; j++)
{
superArray = new int[i*2][j*2];
superArray[i][j] = twoD[i][j];

}
}
return superArray;
}
• 01-20-2011, 07:28 AM
smokinjoachim
A little progress
So i worked on the code a little and this is what i came up with, it works if twoD is 5,6 but if it is 5,7 it does not work.

public static int [][] double2D(int [][]twoD)
{
int [][] superArray = new int[twoD.length*2][twoD.length + 1];
for(int i = 0; i < twoD.length; i++)
{
for(int j = 0; j < twoD[i].length; j++)
{
superArray[i][j] = twoD[i][j];
}

}
return superArray;
}