$30 off During Our Annual Pro Sale. View Details »

CSE110 Lecture 29

CSE110 Lecture 29

Principles of Programming with Java
Bidimensional Arrays
(201707)

Javier Gonzalez-Sanchez
PRO

July 03, 2017
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. CSE110
    Principles of Programming
    with Java
    Lecture 31:
    Bidimensional Arrays
    Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu
    Office Hours: By appointment

    View Slide

  2. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 2
    One-dimensional Array
    • A one-dimensional array stores a list of elements
    0
    0
    0
    0
    0
    0
    0
    1
    2
    3
    4
    5
    int []array = new int [6]
    array

    View Slide

  3. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 3
    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

    View Slide

  4. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 4
    Two-dimensional Array
    • A two-dimensional array is an array of arrays
    • A two-dimensional array is declared by specifying
    the size of each dimension separately
    int[][] scores = new int[12][50];
    • A array element is referenced using two index
    values
    value = scores[3][6]

    View Slide

  5. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 5
    Two-dimensional Array
    The array stored in one row can be specified using
    one index

    View Slide

  6. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 6
    Example 1

    View Slide

  7. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 7
    Example 2

    View Slide

  8. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 8
    Reference
    Section 6.7 page 282

    View Slide

  9. CSE110 - Principles of Programming
    Javier Gonzalez-Sanchez
    [email protected]
    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.

    View Slide