Originally posted by asha ganapathy:
...the result i get are not the elements of the array, it looks like [I@187c6c7...
Actually, you
are getting the elements of the array.
Remember, in
Java, multi-dimensional arrays are really just arrays that contain other arrays. When you say
for(int[] n : a), this means for each
int array (referenced by n) that is an element of the array a. So when you print n, you get a String representation of
the array itself (which is an object) --
not the contents of that array.
(In this case, the String representation uses the left bracket "[" to indicate an array, "I" to indicate the type of array as int, followed by a memory address.)
If you want to print the
contents of this array (n), you will need to iterate through the elements of n. And since this is a multi-dimensional array (arrays within arrays), that's where nested loops come in. In
psuedo code (lacking the iteration details)...