Hi - I'm making a program to calculate PI to n number of decimal places, the calculations are all going fine and now I want to combine values from two arrays into one 2D array for quick reference. I'm a-little confused on how to do this. It should go like this:
There will never be more than two columns for each row, but the number of rows can be any number.
xVals is the first array.
quantVals is the second array.
Both are of type double as is the 2D array.
2Darray[0][0] = xVals[0]
2Darray[0][1] = quantVals[0]
Next row, continue as above....
This seems simple enough to me but in actual practice I can't seem to do it. This is what I have so far:
// Number of columns determined by user's choice - the number of rows will always be
// 2 for each column because each x value has only one quantity value
int maxCol = 2;
double[][] allVals = new double[length][maxCol];
for( int i = 0; i < length; i++ )
{
for( int j = 0; j < maxCol; j++ )
{
allVals[i][j] = xVals[i];
}
}
I am correct in assuming that the first square brackets when declaring an array determines the number of rows so to speak and the next the number of columns? Therefore if i did this:
int [][] myArray = new int[5][4];
...this would create an array with enough space for 20 values of type integer?
Cheers