Skip to content
Justice Tech School

Two Dimensional Arrays

An array of arrays models grids and tables.

Example
public class Main {
  public static void main(String[] args) {
    int[][] g = {{1, 2, 3}, {4, 5, 6}};
    int sum = 0;
    for (int[] row : g) for (int v : row) sum += v;
    System.out.println(g[1][2] + " " + sum + " " + g.length + "x" + g[0].length);
  }
}

Result

6 21 2x3

Exercise

Row count.

g.

Quiz Test

What is g[1][2]?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.