access 2d array by specify 1 dimension in java code example

Example 1: Multidimensional array in java

// how to fill a 2d array java
public class Fill2dArrayExample
{
   public static void main(String[] args) 
   {
      int[][] arrNumbers = new int[3][3];
      for(int a = 0; a < 3; a++)
      {
         for(int b = 0; b < 3; b++)
         {
            arrNumbers[a][b] = (int) (Math.random() * 6) ;
         }
      }
      for(int x = 0; x < 3; x++)
      {
         for(int y = 0; y < 3; y++)
         {
            System.out.print(arrNumbers[x][y] + " ");
         }
         System.out.println();
      }
   }
}

Example 2: Multidimensional array in java

// Syntax Multidimensional array in java
datatype[1][2]...[nth dimension] arrayname = new datatype[1][2]...[nth size];

Tags:

Java Example