COP 3502 Chapter 8: Multidimensional Arrays
Document Summary
Data in a matrix or table can be represented in a 2d array. A 2d array is a 1d array within a 1d array. Declaring variables of 2d arrays and creating 2d arrays. //declaration and initialization elementtype[][] arrayrefvar=new elementtype[rowsize][colsize]; elementtype[][] arrayrefvar={{row0elements}, {row1elements}, {row2elements}}; e. g int matrix[][]=new int[3][3]; Obtaining the lengths of two-dimensional arrays arrayrefvar. length returns the length of the outer array (number of rows). arrayrefvar[row]. length returns the length of the inner array (number of columns or number of elements in a row). When rows of an array have different lengths. Nested for loops are often used to process 2d arrays. for(int row=0; row