On Jun 29, 1:19 pm, Bong <[email protected]> wrote:

>         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;
When you add i+j+k to myNum1 you cause a hole in the indexes.
A three dimensionnal array is just an array of two dinmensional array,
and the same for a n-dimensionnal array.
Hence your loop are the same for every dimension, except that in the
most inner one, you should add 1 to the num.
So:
myNum1 = myNum1+1;

Proof of concept:
i = 0
j = 0
k = 0
myNum1 = 1001

i = 0
j = 0
k = 1
myNum1 = 1002

i = 0
j = 1
k = 0
myNum1 = 1003

...

(first loop on k, then on j (and innerly on k), then on i (and innerly
on j, in turn innerly on k)

See you have to change the initial value of myNum1 to begin with 1000.

Hope this helps.
--~--~---------~--~----~------------~-------~--~----~
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