CS102 · Annotated SlidesChapter 8 — Multidimensional Arrays
Chapter 8 · Annotated slides

Multidimensional Arrays

Declaring and creating 2D arrays, initializers, lengths, ragged arrays, the processing loops (input, random, print, sum, column sums), passing 2D arrays to methods, and 3D arrays.

Slide text Study notes Highlight: key words Tips, tricks & traps Seen again elsewhere How it can come up

Multidimensional Arrays

CS102 · Liang, Chapter 8
1
Slide 2: Motivations
Exam weight Low
    Slide 3: Motivations
    Exam weight Low
      Slide 4: Declare/Create Two-dimensional Arrays
      Exam weight Low
      1. int[][] matrix = new int[5][5]; matrix[0][0] = 3;
      Slide 5: Declaring Variables of Two- dimensional Arrays and Creating Two-dimensional Arrays
      Exam weight Low
        Slide 6: Two-dimensional Array Illustration
        Exam weight Low
          Slide 7: Declaring, Creating, and Initializing Using Shorthand Notations
          Exam weight Low
            Slide 8: Lengths of Two-dimensional Arrays
            Exam weight High
            1. matrix.length = number of rows; matrix[0].length = columns of row 0.
            🎯 How this can come up · 1 question
            MCQ

            For int[][] m = new int[3][4];, m.length and m[0].length are:

            Slide 9: Lengths of Two-dimensional Arrays, cont.
            Exam weight Low
              Slide 10: Ragged Arrays
              Exam weight Medium
              1. Ragged arrays: rows of different lengths: new int[5][] then each row separately.
              Slide 11: Ragged Arrays, cont.
              Exam weight Low
                Slide 12: Processing Two-Dimensional Arrays
                Exam weight Low
                  Slide 13: Initializing arrays with input values
                  Exam weight Low
                    Slide 14: Initializing arrays with random values
                    Exam weight Low
                      Slide 15: Printing arrays
                      Exam weight Low
                        Slide 16: Summing all elements
                        Exam weight Low
                        1. Sum all: nested for over rows and columns.
                        Slide 17: Summing elements by column
                        Exam weight High
                        1. Column sums: outer loop over columns, inner over rows.
                        🎯 How this can come up · 1 question
                        Written

                        Write code that sums each column of int[][] m.

                        Slide 18: Passing Tow-Dimensional Arrays to Methods
                        Exam weight Low
                        1. Pass a 2D array: public static int sum(int[][] m).
                        Slide 19: Multidimensional Arrays
                        Exam weight Low
                        1. 3D arrays: double[][][] scores = new double[6][5][2];
                        Slide 20: Multidimensional Arrays
                        Exam weight Low