Hi Sunil

Please try this:

   /**
     * @author mihai 2012-02-28
     */
   public class TestMultiArray {

        public static void main(String[] args) {
   // Array of arrays of int, instantiated as a 3 element array
            // (each element is an array of int)
            int[][] myArray = new int[3][];
            for (int i = 0 ; i < myArray.length ; i++ ){
   // Instantiate each element of the Array with an array of int
                // of random size (I don't know how many ints are in
   the array)
                myArray[i] = new int[(int)Math.round(1 + 10 *
   Math.random())];
   // For each element of the array (which is an element of the Array)
                for (int j = 0 ; j < myArray[i].length ; j++){
   // ... assign a value in sequence
                    myArray[i][j] = j;
                }
            }
   // Now print all the elements of the Array:
            for (int[] a : myArray){// For each element a of the Array
   (an array)
                for (int n : a){// for each element n of the array
                    System.out.print("\t" + n);// Print tab-separated
   values
                }
   // Pass to the next line
                System.out.println();
            }
        }
   }

The printed result may vary from one execution to another (due to the "random"), for e.g.:
*    0    1
    0    1    2    3    4    5    6    7    8    9
    0    1    2    3    4    5*

Hope it helps
Mihai

On 28/02/2012 04:51, sunil atluri wrote:
I understand that you can use<array name>.length property toknow the
length and loop through to get values for specific element of a single
dimensional array.
Is it possible to do the same (instead of harcoding) for a
multidimensional array? If so, can you show me an example?

Thanks
Sunil Atluri


--
You received this message because you are subscribed to the Google Groups 
"JPassion.com: Java Programming" group.
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/jpassion_java?hl=en.

Reply via email to