1 d & 2 d array syntax java code example
Example 1: 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 2: Multidimensional array in java
public class TwoDimensionalArrayLength
{
public static void main(String[] args)
{
int[][] arrNumber = {
{ 1, 3, 5 },
{ 7, 9, 2 },
{ 1, 2, 3, 4, 5 } };
System.out.println("Java two dimensional array length: " + arrNumber.length);
}
}