8.1 Two-Dimensional Arrays

    Cards (43)

    • A two-dimensional array organizes elements in rows and columns
    • Declaring a 2D array in Java initializes all elements to the default value, which is 0
    • You declare a 2D array in Java by specifying the number of rows and columns.

      True
    • Each element in a 2D array is accessed using two indices: one for the row and one for the column.

      True
    • What is the default value for elements in a 2D array of integers when declared in Java?
      0
    • How do you access an element in a 2D array named `arrayName` with row index `r` and column index `c`?
      arrayName[r][c]
    • What is the purpose of a row index and a column index when accessing elements in a 2D array?
      Specify the element position
    • How do you access an element in a 2D array using row and column indices?
      grid[row][column]
    • Steps to iterate through a 2D array using nested loops
      1️⃣ Outer loop iterates through the rows
      2️⃣ Inner loop iterates through the columns
      3️⃣ Access each element using row and column indices
    • What does the outer loop in nested loops for a 2D array iterate through?
      Rows
    • How do you declare a 2D array in Java with 3 rows and 4 columns?
      int[][] grid = new int[3][4];
    • Match the 2D array concepts with their descriptions:
      Declaration ↔️ Creates the array structure
      Initialization ↔️ Assigns default values
      Iteration ↔️ Accesses each element
      Accessing ↔️ Uses row and column indices
    • A 2D array organizes elements in rows and columns.

      True
    • All elements in a newly created 2D array of integers in Java are initialized to 0.
      True
    • When initializing a 2D array in Java, all elements are set to their default value.

      True
    • Steps to iterate through a 2D array using nested loops
      1️⃣ Outer loop iterates through the rows
      2️⃣ Inner loop iterates through the columns for each row
      3️⃣ Use row and column indices to access elements
    • To manipulate elements in a 2D array, you use row and column indices to assign new values
    • What is a two-dimensional array, or 2D array, in computer science?
      A data structure
    • How do you declare a 2D array of integers in Java with 3 rows and 4 columns?
      int[][] grid = new int[3][4];
    • How do you access the element in the second row and third column of a 2D array named `grid`?
      grid[1][2]
    • A two-dimensional array is also known as a 2D array.
    • To declare a 2D array in Java, you use the keyword new.
    • What is the syntax for declaring a two-dimensional array in Java?
      dataType[numRows][numColumns]
    • To access individual elements in a 2D array, you use both a row index and a column index.
    • The `grid[row][col]` syntax accesses the element at the current row and column during nested loop iteration.
      True
    • Each element in the 2D array is accessed using two indices
    • Here's how you declare a 2D array in Java
    • To access the element in the second row and third column of a 2D array named `grid`, you would use grid[1][2]
    • To access individual elements in a 2D array, you use both a row index and a column index
    • The outer loop in nested loops for 2D arrays iterates through the columns.
      False
    • What value would replace `grid[0][1]` after the statement `grid[0][1] = 10` in the given example?
      10
    • The syntax for declaring a 2D array in Java is `dataType[][] arrayName = new dataType[numRows][numColumns];`, where `numRows` and `numColumns` specify the number of rows and columns
    • All elements in a newly declared 2D array of integers are initialized to 0.

      True
    • When a 2D array of integers is initialized in Java, all elements are set to 0 by default.

      True
    • The index `grid[1][2]` refers to the element in the second row and third column.

      True
    • To iterate through a two-dimensional array, you use nested loops
    • A two-dimensional array organizes elements in rows and columns
    • When a 2D array is created in Java, all integer elements are initialized to 0.

      True
    • What is a two-dimensional array also known as?
      2D array
    • How do you create a 2D array in Java with 3 rows and 4 columns?
      int[][]grid=int[][] grid =newint[3][4] new int[3][4]
    See similar decks