4 Dimensional Arrays in Java
Sample code for 4 Dimensional Arrays in Java
package javaArrays;
import java.util.Scanner;
public class FourDimArray {
public static void main(String[] args) {
int a[][][][] = new int[5][4][3][2];
int i,j,k,l, num = 1;
for (i=0; i<5; i++)
{
for(j=0; j<4; j++)
{
for(k=0; k<3; k++)
{
for(l=0; l<2; l++)
{
a[i][j][k][l] = num;
num++;
}
}
}
}
for(i=0; i<5; i++)
{
for(j=0; j<4; j++)
{
for(k=0; k<3; k++)
{
for(l=0; l<2; l++)
{
System.out.print(“a[“ +i+ “][“ +j+ “][“ +k+ “][“ +l+ “] = “ +a[i][j][k][l]+ “\t”);
}
System.out.println();
}
System.out.println();
}
System.out.println();
}
}
}