I am doing a cash registry program and I want to use a multidimensional array. May someone give me a sample code for it. The sample code must be as simple as possible just for my reference. Reply will be appreciated very much.

Can you tell us more detail about your requirements ? Also multidimensional array you use Google to find java sample codes for this.

int[][][] testArray = new int[10][5][5];

That is the syntax for a 3 dimension array of ints.

int [] onedee;
int [][] twodee;
int [][][] threedee;
//so on

import java.util.Random;



public class Main
{
    public static void main(String[] args)
    {
        int [][]twodee =
        {
            {0,0,0},
            {0,0,0}
        };

        Random rand = new Random();
        //populate
        for(int i = 0; i < twodee.length; i++)
        {
            for(int j = 0; j < twodee[i].length; j++)
            {
                twodee[i][j] = rand.nextInt(100);
            }
        }
        //print
        for(int i = 0; i < twodee.length; i++)
        {
            for(int j = 0; j < twodee[i].length; j++)
            {
                System.out.print(twodee[i][j] + "\t");

            }
        }
    }

}

Read the article - Arrays

SUMMARY: In the Java programming language, a multidimensional array is simply an array whose components are themselves arrays. This is unlike arrays in C or Fortran.

This article has been dead for over six months. Start a new discussion instead.