PDA

Click to See Complete Forum and Search --> : dynamic 3-D array


sriya
Sep 28th, 2007, 02:35 AM
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)




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!!

ComputerJy
Sep 28th, 2007, 03:56 AM
Your not that good at explaining what you want to do. but I hope this code sample is helpful

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();
}
}