Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Three Dimensional Array program in Java.

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 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.

Reply With Quote
  #2  
Old 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();
   }
  }
}
Reply With Quote
  #3  
Old 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.
Reply With Quote
  #4  
Old 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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Three Dimensional Array program in Java."
Thread Thread Starter Forum Replies Last Post
Program to print an 2D array Sarfaraj Khan Software Development 5 03-02-2010 02:59 PM
Help with two dimensional array java GlassFish Software Development 3 30-11-2009 01:57 PM
Two dimensional array to a function Chrisch Software Development 3 27-11-2009 12:47 PM
How to store space in a array in a C program NetworkeR Software Development 3 03-11-2009 12:41 PM
Dynamically allocate a two-dimensional array Chrisch Software Development 3 24-10-2009 11:43 AM


All times are GMT +5.5. The time now is 03:17 AM.