Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE110 Lecture 30

CSE110 Lecture 30

Principles of Programming with Java
Multidimensional Arrays
(201705)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

July 04, 2017
Tweet

Transcript

  1. CSE110 Principles of Programming with Java Lecture 32: Multidimensional Arrays

    Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 2 One-dimensional

    Array • A two-dimensional array can be thought of as a table of elements, with rows and columns 0 1 2 3 4 5 int [][]array = new int [6][3] array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2
  3. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 3 Reality

    (2D Array)
  4. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 4 Example

    2 0 1 2 3 scores 3 4 5 2 4 3 3 5 4 1 1 1 0 1 2 ... // y, x
  5. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 5 Multidimensional

    Arrays • An array can have many dimensions – if it has more than one dimension, it is called a multidimensional array • Each dimension subdivides the previous one into the specified number of elements • Each dimension has its own length constant • Because each dimension is an array of array references, the arrays within one dimension can be of different lengths
  6. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 6 int

    [][][] FourByThreeByTwo = { { {1,2}, {2,4}, //z, y, x {3,6} }, { {2,4}, {4,8}, {6,12} }, { {3,6}, {6,12}, {9,18} }, { {4,8}, {8,16}, {12,24} } }; 12 24 8 16 4 8 9 18 6 12 3 6 6 12 4 8 2 4 3D Array 3 6 2 4 1 2
  7. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 7 Test

    Yourselves
  8. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 8 Test

    Yourselves
  9. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 9 Reference

    Section 6.7 page 282
  10. CSE110 - Principles of Programming Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2017

    Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.