I got it now. Thanks to Mihai for the thorough explanation. Encore une fois, merci :)
On Feb 12, 4:58 pm, Mihai DINCA <mihai.di...@free.fr> wrote: > Hi Michel > > The statements : > -- SomeType[ ] ages = null; > declares a variables to be used as an array of objects of SomeType. > > -- ages = new SomeType[ 3 ]; > creates a three elements array (each element is empty: > System.out.println(ages[i]) will print "null"). > > -- for ( int i = 0 ; i < ages.length ; i++ ) ages[i] = new SomeType(); > stores in each element of the array an object of SomeType > > Imagine now that SomeType is int[ ] > > Then: > -- int[ ][ ] ages = new int[3][ ]; > declares a variable to be used as an array of three elements, > each element will be an array of int, > each element is for the moment null > > -- for ( int i = 0 ; i < ages.length ; i++ ) ages[i] = new int[4]; > associates to each element of the array "ages" an array of four > integers. > > The same thing can be written as: > -- int[ ][ ] ages = new int[3][4]; > > Now: > -- ages is an array of three elements, each element being an array of > four integers > -- ages is an array of arrays > -- ages[2] is an array of integers > -- ages[2][1] is an integer > -- for ( int i = 0 ; i < ages.length ; i++ ){ // for each of the 3 > arrays in ages > for ( int j = 0 ; i < ages[i].length ; j++ ) { // for each of > the 4 integers in the i-th array > ages[ i ][ j ] = i * j; // The j-th integer in the i-th > array set to i * j > } > } > > Hope it helps > > Mihai > > Le 12/02/2011 15:34, Michel a crit : > > > Hello folks, > > Can someone please help me understand this part of the code from > > LAB-1036: Exercise 1, part 2? > > > // Display the value of each entry in the array > > for( int i=0; i<ages.length; i++ ){ > > System.out.println("\nStarting row " + i); > > for( int j=0; j<ages[i].length; j++ ){ > > ages[i][j] = i * j; > > System.out.print( ages[i][j] + " " ); > > > When we say ages[i][j] = i * j; does that mean that if for instance > > i=2 and j=2 then the array will display as number 4 (2*2=4)? I guess > > what I don't understand is how an array that is represented as rows > > and columns can equal a number (since i * j is a number)? > > -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en