|
-
Sep 28th, 2007, 02:35 AM
#1
Thread Starter
Lively Member
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!!
-
Sep 28th, 2007, 03:56 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|