The Array2DMultiples class contains two static methods that work with two-dimensional arrays.
The first method, buildMatrix, constructs and returns a two-dimensional array.
arr : a one-dimensional array of integerscols : the number of columns for the two-dimensional arrayarr determines the number of rows.cols determines the number of columns.arr.Given:
int[]arr = {7,6,2,6};
int cols =5;
The resulting array will have:
Row 0 (multiples of 7): 7 14 21 28 35
Row 1 (multiples of 6): 6 12 18 24 30
Row 2 (multiples of 2): 2 4 6 8 10
Row 3 (multiples of 6): 6 12 18 24 30
/**
* Builds a two-dimensional array using the length of arr as the number of rows
* and cols as the number of columns.
*
* @param arr the array containing the base values
* @param cols the number of columns in the resulting matrix
* @precondition arr.length > 0, cols > 0
* @postcondition returns the constructed two-dimensional array
*/
publicstaticint[][]buildMatrix(int[]arr,intcols)
{
/* implementation not shown */
}