Java – two dimensional array example

Java – two dimentional array example

import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    int[][] arr = new int[3][10];  // 3 rows, 10 columns
    Arrays.fill(arr[0], 1);  // 1st row fill all columns values by 1
    Arrays.fill(arr[1], 2);  // 2nd row fill all columns values by 2
    Arrays.fill(arr[2], 3);  // 3rd row fill all columns values by 3
    for (int[] row: arr) {
      for(int v: row) {
        System.out.print(v + " ");
      }
      System.out.println("");
    }
  }
}
OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory file:
   1686
Try using the -Djava.io.tmpdir= option to select an alternate temp location.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments