1 / 6

Understanding 2D Arrays with Uneven Rows: Storing and Accessing Values

This guide explains the concept of 2D arrays, specifically focusing on arrays with uneven numbers of cells per row. We will determine the values stored in specific cells of the 2D array `gradeTable` and the non-uniform `uneven` array. The example showcases how to declare and construct these arrays, followed by a practical demonstration of printing their contents. Emphasizing the relationship between arrays and references to 1D arrays, this resource is essential for understanding advanced array structures in programming.

kalila
Download Presentation

Understanding 2D Arrays with Uneven Rows: Storing and Accessing Values

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Warm up • Determine the value stored in each of the following: • gradeTable[ 0 ][ 0 ] • gradeTable[ 1 ][ 1 ] • gradeTable[ 3 ][ 4 ] • gradeTable[ 5 ][ 2 ]

  2. More 2-D Arrays

  3. Different Numbers of Cells per Row • Usually you think of a 2D array as a table • Is this possible:int[][] uneven = {{ 1, 9, 4 }, { 0, 2}, { 0, 1, 2, 3, 4 }};

  4. Different Numbers of Cells per Row • You have to think of "arrays of references to 1D arrays.“

  5. Different Numbers of Cells per Row • Determine the value stored in each of the following: • uneven[ 0 ][ 0 ] • uneven[ 1 ][ 1 ] • uneven[ 0 ][ 4 ] • uneven[ 2 ][ 4 ]

  6. Printing a 2D Array // declare and construct a 2D array int[][] uneven = { { 1, 9, 4 }, { 0, 2}, { 0, 1, 2, 3, 4 } }; // print out the array for(int row=0; row < uneven.length; row++) { System.out.print("Row " + row + ": "); for(int col=0; col < uneven[row].length; col++) System.out.print(uneven[row][col] + " "); System.out.println(); }

More Related