Results 1 to 2 of 2

Thread: dynamic 3-D array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    82

    dynamic 3-D array

    hi all,
    i'm jst struggling of making a dynamic 3-D array.
    here is the code.
    is it possible to bouild up arrays of bojects with different sizes of width and height? (as in the 3rd line of the code shown)




    Code:
    MyObject[][][] user_stories = new MyObject[no_f_projects][][]; 
    
    for(i=0; i < no_f_projects; i++){
    	user_stories = new UserStoryData[no_f_projects][no_f_iterations[i]][];
    	for(j=0; j<no_f_iterations[i]; j++){
    		user_stories[i][j] = planner.getUserStories(Id[i][j]);
     	}	
    }

    here in the 5th line.. an array of objects is passed to the reference user_stories.........
    pls help me
    thanking in advance!!

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: dynamic 3-D array

    Your not that good at explaining what you want to do. but I hope this code sample is helpful

    Code:
        public static void main(String[] args) {
            Random rand = new Random();
            int[][][] myArray = new int[10][][];
            for (int i = 0; i < myArray.length; i++) {
                myArray[i] = new int[i][];
                for (int j = 0; j < myArray[i].length; j++) {
                    myArray[i][j] = new int[j + 1];
                    for (int k = 0; k < myArray[i][j].length; k++) {
                        myArray[i][j][k] = rand.nextInt(100);
                    }
                }
            }
    
            print(myArray);
        }
    
        private static void print(int[][][] myArray) {
            for (int i = 0; i < myArray.length; i++) {
                for (int j = 0; j < myArray[i].length; j++) {
                    for (int k = 0; k < myArray[i][j].length; k++) {
                        System.out.print(" " + Integer.toString(myArray[i][j][k]));
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width