Introduction to Java: Two Dimensional Arrays

Introduction to Java: Two Dimensional Arrays

This example prints the contents of a two dimensional array.

TwoDimensionalArrays.java

 1 package twodimensionalarrays;
 2 
 3 public class TwoDimensionalArrays {
 4 
 5     public static void main(String[] args) {
 6         int[][] b = {{2, 5}, {11, 3}};
 7 
 8         for (int i = 0; i < b.length; i++) {
 9             for (int j = 0; j < b[i].length; j++) {
10                 System.out.print(b[i][j] + " ");
11             }
12             System.out.println();
13         }
14     }
15 }
16 

Return to top