Copying content from a two dimentional array to another

Hey

I have some 2d arrays that looks like this:

int[][] numbers ={{0,1,2,3,4,5},{2,2,3,3,2,2},{5,4,5,4,5,4},{1,0,2,9,8,3},{4,5,9,2,5,6},{3,3,0,0,0,0}};

int[][] numbers2={{0,1,2,3,4,5},{2,2,3,3,2,2},{5,4,5,4,5,4},{1,0,2,9,8,3},{4,5,9,2,5,6},{3,3,0,0,0,0,}};

int[][] numbers3={{0,1,2,3,4,5},{2,2,3,3,2,2},{5,4,5,4,5,4},{1,0,2,9,8,3},{4,5,9,2,5,6},{3,3,0,0,0,0}};

and ono other array where I want to store this data like this:

int[][] numb ={{0,1,2,3,4,5,2,2,3,3,2,2,5,4,5,4,5,4,1,0,2,9,8,3,4,5,9,2,5,6,3,3,0,0,0,0},{1,2,3,4,5,2,2,3,3,2,2,5,4,5,4,5,4,1,0,2,9,8,3,4,5,9,2,5,6,3,3,0,0,0,0},{1,2,3,4,5,2,2,3,3,2,2,5,4,5,4,5,4,1,0,2,9,8,3,4,5,9,2,5,6,3,3,0,0,0,0}};

In other words I want to take all data from numbers and put them in one row in numb(numbers2 in other and so on). I need to store them this way because I have to use them later, all data from numbers at a time, and so on.

Any ideas. Now I have been strugeling with this fir 2 days. Tnx

[2438 byte] By [PhpDudea] at [2007-11-27 0:26:57]
# 1

Hi

Is this code will work for you

class arrdemo

{

public static void main(String[] args)

{

int[][] numbers1 = {{0,1,2,3,4,5},{2,2,3,3,2,2},{5,4,5,4,5,4},{1,0,2,9,8,3},{4,5,9,2,5,6},{3,3,0,0,0,0}};

int[][] numbers2= {{0,1,2,3,4,5},{2,2,3,3,2,2},{5,4,5,4,5,4},{1,0,2,9,8,3},{4,5,9,2,5,6},{3,3,0,0,0,0,}};

int[][] numbers3= {{0,1,2,3,4,5},{2,2,3,3,2,2},{5,4,5,4,5,4},{1,0,2,9,8,3},{4,5,9,2,5,6},{3,3,0,0,0,0}};

int numbers[][]=new int[3][36];

int s=0,k=0,i,j;

for (i=0;i<6;i++)

{

for (j=0;j<6;j++)

{

numbers[0][k++]=numbers1[i][j];

}

}

k=0;

for (i=0;i<6;i++)

{

for (j=0;j<6;j++)

{

numbers[1][k++]=numbers2[i][j];

}

}

k=0;

for (i=0;i<6;i++)

{

for (j=0;j<6;j++)

{

numbers[2][k++]=numbers3[i][j];

}

}

System.out.println(" -+"+k+"\n");

for (i=0;i<3;i++)

{

for (j=0;j<36;j++)

{

System.out.print(" "+numbers[i][j]);

}

System.out.println("\n");

}

}

}

EXCEPTIONa at 2007-7-11 22:26:07 > top of Java-index,Java Essentials,Java Programming...
# 2

can u try something like this:

int x= 0;

for(int i= 0, k= 0;i<6;i++) {

for(int j= 0;j<6;j++) {

numb[x][k++]= numbers2[i][j];

}

}

x++;

// Work for next loop

varun_koteshwara at 2007-7-11 22:26:07 > top of Java-index,Java Essentials,Java Programming...
# 3

Yeah ,tnx it worked out.

This was perfect, but almost: It puts values from numbers2 in all of them

int x= 0;

for(int i= 0, k= 0;i<6;i++) {

for(int j= 0;j<6;j++) {

numb[x][k++]= numbers2[i][j];

}

}

x++;

It would be better if I could write something like this:

int x= 0;

int numberOfArrays=3; //I have the total number of arrays

for(int i =0; i<numberOfArrays; a++)

{

for(int i= 0, k= 0;i<6;i++) {

for(int j= 0;j<6;j++) {

numb[x][k++]= numbers+numberOfArrays+[i][j]; //but this is not the right way to concat this ?

}

}

x++;

}

>

PhpDudea at 2007-7-11 22:26:07 > top of Java-index,Java Essentials,Java Programming...