Filling a 2D array with other arrays.

I am completely novice to the 2D arrays but so far I have been grasping the concept. Except one issue. I have an assignment that in one of the methods, a multi-dimensional array with columns and rows with lengths of other arrays, must be built. That part is done, and I figured out by now that I need a for loop within another for loop to fill it with the content of 2 other separate arrays. So I have:

Code :

int [] sot = {20, 25, 30, 35, 40, 45, 50};
int [] fet = {25, 30, 35, 40, 45, 50};
double[][] myHUT = new double [sot.length][fet.length];
public void trackerUlt(){
for (int row = 0; row < myHUT.length; row++)
for (int col = 0; col < myHUT[0].length; col++)
myHUT[row][col] += //???needs sot and fet array data in there.
}

I just don't know how to make it so that I have all the numbers from **sot** and all the numbers from the **fet** array filled into the myHUT multi-dimensional array. Help me out.

Re: Filling a 2D array with other arrays.

You should think about the sizes of the arrays you are working with and where the element in the two single dim arrays are to go. The two dim arrays have 7 and 6 elements for a total of 13 elements. The 2 dim array has 7x6 slots for a total of 42 elements. There are a few extra slots in the 2 dim array. What do you want to put in them?

You can treat the 2 dim array as an array of arrays:

if twoDim has two dim and oneDim has one dim then:

twoDim[i] = oneDim; // assign the one dim array to one of the rows of the 2 dim array

Re: Filling a 2D array with other arrays.

What is **i** in your example? So in comparison to my example, you mean set it up like:

Code :

myHUT[0][] = sot[];
myHUT[1][] = fet[];

wouldn't that mean not using the for loops then? I sort of need to use those.

Re: Filling a 2D array with other arrays.

Leave off the '[]'s.

As I said before the two 1 dim arrays have 13 elements and the 2 dim array has 42.

What goes in those extra slots?

Re: Filling a 2D array with other arrays.

Hmmm, well in the output there is supposed to be 42 numbers of data, 7 per column. So I don't really know....

Ahh stupid me. After the second for loop, a formula must be added to take the calculations of both arrays, and adds that to the 2-dim array. Not just the numbers themselves.