TechArena Community Three Dimensional Array program in Java.

# Three Dimensional Array program in Java.

## Software Development

#1
10-08-2009
 Member Join Date: May 2008 Posts: 30
Three Dimensional Array program in Java.

Hello,

I am not very good at 2 dimensional arrays in Java. But I need to know the 3 dimensional array working in java. If someone could help me with a simple 7 working example it will be helpful for me.

All I need is a Three Dimensional Array program in Java.

#2
10-08-2009
 Member Join Date: May 2008 Posts: 22
Re: Three Dimensional Array program in Java.

How to use three dimensional array.

This is a very simple Java program. Firstly, we have to define class name "ThreeDMatrix" . We are going to create 3 by 4 by 5 program. We are going to make three dimensional array having multi rows and columns.

By using the multidimensional array we are going to make a matrix. Now in this program use the three for loop for multi dimensional array. After that use the display the values by using println() method .

Code:
```class ThreeDMatrix
{
public static void main(String[] args)
{
int threeD[][][] = new int[3][4][5];
int i,j,k;
for (i=0; i<3; i++)
for(j=0; j<4; j++)
for (k=0; k<5; k++)
threeD[i][j][k]= i*j*k;

{
for(i=0; i<3; i++)
for(j=0; j<4; j++){
for (k=0; k<5; k++ )
{
System.out.print(threeD[i][j][k]);
}
System.out.println();
}
System.out.println();
}
}
}```
#3
10-08-2009
 Member Join Date: May 2008 Posts: 27
Re: Three Dimensional Array program in Java.

JAVA Multi-Dimensional Arrays

ANY TYPE CAN BE USED AS THE BASE TYPE FOR AN ARRAY. You can have an array of ints, an array of Strings, an array of Objects, and so on. In particular, since an array type is a first-class Java type, you can have an array of arrays. For example, an array of ints has type int[]. This means that there is automatically another type, int[][], which represents an "array of arrays of ints". Such an array is said to be a two-dimensional array. Of course once you have the type int[][], there is nothing to stop you from forming the type int[][][], which represents a three-dimensional array -- and so on. There is no limit on the number of dimensions that an array type can have. However, arrays of dimension three or higher are fairly uncommon, and I concentrate here mainly on two-dimensional arrays. The type BaseType[][] is usually read "two-dimensional array of BaseType" or "BaseType array array".

The declaration statement "int[][] A;" declares a variable named A of type int[][]. This variable can hold a reference to an object of type int[][]. The assignment statement "A = new int[3][4];" creates a new two-dimensional array object and sets A to point to the newly created object. As usual, the declaration and assignment could be combined in a single declaration statement "int[][] A = new int[3][4];". The newly created object is an array of arrays-of-ints. The notation int[3][4] indicates that there are 3 arrays-of-ints in the array A, and that there are 4 ints in each array-of-ints. However, trying to think in such terms can get a bit confusing -- as you might have already noticed. So it is customary to think of a two-dimensional array of items as a rectangular grid or matrix of items. The notation "new int[3][4]" can then be taken to describe a grid of ints with 3 rows and 4 columns.
#4
10-08-2009
 Member Join Date: Apr 2008 Posts: 22
Re: Three Dimensional Array program in Java.

Three Dimensional Array

A Simulation of the Java Virtual Machine

This example will also be helpful for you to understand the three dimensional arrays with simulation of JVM.