COP 3502 Chapter 8: Multidimensional Arrays

50 views2 pages

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

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers