Ages[2].length = ages[0][1].length
De: [email protected] [mailto:[email protected]] En nombre de Eric Cai Enviado el: lunes, 10 de agosto de 2009 9:34 Para: [email protected] CC: [email protected] Asunto: [java programming] Re: three dimensional array LAB 1036 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 <http://www.fingermoney.co.za/> <br --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
