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.

Recommended Answers

All 4 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.