0

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.

5
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by __avd
0

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

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

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

0

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");

            }
        }
    }

}
0

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.
Be sure to adhere to our posting rules.