0

okay i was told to do a 3d array of ints named x blah blah, with 3 rows and 2 columns with 4 ints in each column. The elements in the first row are all 5, in the second row are all 7, and in the third row the first column is all 8 and the second column is 30, 31, 32, and 33.

int[][][] x = new int[3][2][]= {{5,5,5,5},{7,7,7,7},{8,30,31,32,33}};

this is what i came up with but im not sure about applying values to a "column"

yeah this is homework but im confused on what to do futher, this was the exact questions

Declare, create, and initialize a three-dimensional array of ints, x, that has 3 rows, each of which has 2 columns where each column is an array 4 ints. The elements in the first row are all 5, in the second row are all 7, and in the third row the first column is all 8 and the second column is 30, 31, 32, and 33.

1
  • Please post your exact assignment requirements. Something doesn't seem quite right to me. Commented Sep 14, 2012 at 2:44

2 Answers 2

1

Your array will hold 24 items: 3 * 2 * 4. The first row will hold 8 ints since it has 2 columns each holding 4 ints. Best to try to visualize this in your head but not as a flat row x column array, but in 3 dimensions with numbers sticking out of the page.

Also you'll need to nest curly braces 3 deep for this to be a 3-D array. Your attempt currently only nests parenthesis two deep as would be seen in a 2-D array. Since this is homework, we shouldn't solve this for you, but we can help you. So please try again and show us what you come up with.

Edit
Also, your code will not compile, so best to scrap it and try afresh. Again, if you hit a wall, please edit your post and notify us by comment of your changes.

Sign up to request clarification or add additional context in comments.

2 Comments

int[][][] x = new int[][][]= x[0][1]= {5,5,5,5} x[0][2]= {5,5,5,5} x[1][0]= {7,7,7,7} x[1][1]= {7,7,7,7} x[2][0] ={8,8,8,8} x[2][1] ={30,31,32,33} so its kinda something like this.. the array layout i mean
@max: I'm not sure what you mean, but that's not the syntax for initializing arrays on declaration. Please add any code updates as an edit to your answer. Only non-code comments should go here.
0

I pass for the same problem and i found that this works...

`int[][][] x = {{{5,5,5,5},{5,5,5,5}},
           {{7,7,7,7},{7,7,7,7}},
           {{8,8,8,8},{30,31,32,33}}};`

I already tested in eclipse.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.