Hi,

>From Lesson-1036 Java Array,

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.

can someone possibly show me the solution to the said exercise. I've
been trying it out but i don't seem to understand how a 3-dimensional
array is arranged.

Here's my code:

public class JavaThreeDimensionArray {

    // Creates a new instance of JavaThreeDimensionArray
    public JavaThreeDimensionArray() {
    }

    public static void main(String[] args) {

        // Declare and create a three-dimentional int array whose size
is
        // 5 by 2 by 2
        int[][][] myInt = new int[2][2][2];
        int myNum1 = 1000;

        for (int i = 0; i < myInt.length; i++) {
            for (int j = 0; j < myInt[i].length; j++) {
               for (int k = 0; k < myInt[i][j].length; k++) {
                    myNum1 = myNum1 + i + j + k;
                    System.out.print(myNum1 + " ");
                }
            }
        }
    }

And here's my output:
1000 1001 1002 1004 1005 1007 1009 1012

--~--~---------~--~----~------------~-------~--~----~
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