# Thread: Double the size of a 2d

1. Member
Join Date
Jan 2011
Posts
2
Rep Power
0

## 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;
}

2. Member
Join Date
Jan 2011
Posts
2
Rep Power
0

## 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;
}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•