java 2d array access code example
Example 1: accessing 2d array in java
(m x n matrix) - (2 x 3 matrix)
m n ------------------ >
| a[0][0] a[0][1] a[0][2]
v a[1][0] a[1][1] a[0][2]
Example 2: Multidimensional array in java
public class SimpleTwodimensionalArray
{
public static void main(String[] args)
{
int[][] arrnumbers = {{2, 4},{6, 8},{10, 12}};
System.out.println("Two dimensional array in java: ");
for(int a = 0; a < 3; a++)
{
for(int b = 0; b < 2; b++)
{
System.out.println(arrnumbers[a][b]);
}
}
}
}
Example 3: How to create a 2d array in java
int[][] arr = new int[m][n];