Hi,

It is in         System.out.println("ages[2].length = "+ages[2].length);

You see that 2 is out of bounds .
You define an array of size 2. And you should use 0-1 to Index it.

Thanks,
Eric Cai

On Mon, Aug 10, 2009 at 2:47 PM, Quentin <[email protected]> wrote:

>  Good day all
>
>
>
> I have a problem with this three dimensional array.
>
>
>
> Any suggestions?
>
>
>
> [code]
>
>
>
> public static void main(String[] args) {
>
>         // TODO code application logic here
>
>         int[][][] ages = new int[10][5][2];
>
>
>
>         System.out.println("ages.length = "+ages.length);
>
>         System.out.println("ages[1].length = "+ages[1].length);
>
>         System.out.println("ages[2].length = "+ages[2].length);
>
>
>
>         for (int i = 0; i<ages.length; i++)
>
>         {
>
>             System.out.println("\nStarting Row "  +i);
>
>
>
>             for(int j = 0;j<ages[i].length;j++)
>
>             {
>
>                 for(int k = 0;k<ages[k].length; k++)
>
>                 {
>
>                      ages[i][j][k] = i * j * k;
>
>                      System.out.println(ages[i][j][k] + " ");
>
>                 }
>
>             }
>
>         }
>
>     }
>
> [/code]
>
>
>
> My error message I receive is
>
>
>
> [error]
>
>
>
> ages.length = 10
>
> ages[1].length = 5
>
> ages[2].length = 5
>
>
>
> Starting Row 0
>
> 0
>
> 0
>
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
>
>         at TwoDimensionArray.main(TwoDimensionArray.java:31)
>
> Java Result: 1
>
> BUILD SUCCESSFUL (total time: 0 seconds)
>
> [/error]
>
>
>
> REGARDS
>
> Quentin
>
>
>
> *FINGER MONEY*
>
> *http://www.fingermoney.co.za*
>
>
>
> >
>

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