Results 1 to 2 of 2
Thread: Double the size of a 2d
- 01-20-2011, 05:19 AM #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;
}
- 01-20-2011, 06:28 AM #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;
}
Similar Threads
-
double a * double b = weird output
By GPB in forum New To JavaReplies: 3Last Post: 03-26-2010, 10:40 AM -
Check if double is double
By marshalthrone in forum New To JavaReplies: 8Last Post: 09-30-2009, 02:51 PM -
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 04:37 PM -
non-static method add(double,double) cannot be referenced from a static context
By cravi85 in forum Java SoftwareReplies: 5Last Post: 03-21-2009, 09:32 PM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks