Think of your declaration:
int[][][]nums = new int[3][6][9];

as specifying a 3x6x9 rectangular box

the box would be 3 units wide, 6 units long and 9 units high.

nums.length is the width of the box.

nums[0].length is the length at the first width position.
nums[1].length is the length at the second width position
nums[2].length is the length at the third width position

since this is a uniform box, the length at any position is 6

If you want the height of the box at a particular point, you would need to 
specify both a width and length location.
for example:

nums[1][2].length

This should give you the desired value.

Don Mellen




________________________________
From: Shawn Sampson <[email protected]>
To: Free Java Programming Online Training Course By Sang Shin 
<[email protected]>
Sent: Sunday, July 12, 2009 6:07:08 PM
Subject: [java programming] Exercise 1: Build and run Java programs that use 
Java array of int


Build and run a Java program that uses two-dimensional array of int

4. (For your own exercise) Create a NetBeans project as following.
Build and run the program.

Declare and initialize 3-dimensional array of int
Initialize each cell with increasing integer number starting from
1000, 1001, 1002, and so on.
------------------------------------------------------------------------------------------------------------

package threedarray;

/**
*
* @author wagle
*/
public class ThreeDArray {
    public ThreeDArray (){
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //Declare and create three dimensional int
       //array whose size is 3 by 6 by 9
       int[][][]nums = new int[3][6][9];

       //Display the number of rows and columns
       System.out.println("nums.length = " + nums.length);
       System.out.println("nums[1].length = " + nums[1].length);
       System.out.println("nums[2].length = " + nums[2].length);


           }
       }
----------------------------------------------------------------------
output:


run:
nums.length = 3
nums[1].length = 6
nums[2].length = 6
BUILD SUCCESSFUL (total time: 0 seconds)


--------------why is this "not" printing the following.
---------------

nums.length = 3
nums.length = 6
nums.length = 9

is there something I am missing?



      
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to