It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Multi-dim Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Multi-dim Array" Watch "Multi-dim Array" New topic

Multi-dim Array

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
This is from Master exam







The answer is A,B,E,F
I get a little confused with multi dimentsional arrays, even thought i know the rules.
I know while assigning an array they should be of the same dimension
or you can assign a one dimensional to a 2 dimensional array
But it's difficult to implement it when you have arrays like

short b2[][][][]=new short[2][3][2][2];

I get totally lost here..

The only statment that makes sense to me is

Assigning a varibale to the 0 th element of the 1st array of b.


Assigning an element of array b to an element of array b2.

Can some one please help with this.

The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3902

Think of it like a tree structure (that's how I think ).

when you say

[ September 17, 2008: Message edited by: Vijitha Kumara ]

[How to ask questions] [Twitter]
sumi rankan
Ranch Hand

Joined: Apr 07, 2008
Posts: 46
I used a rough thumb rule for this type of question and it worked.
For eg,
short b2 [] [] [] []=new short [2][3][1][2];
while assigning, the dimensions on both sides should match.
Like when you say
b is a 2d array and it has been assigned to the 3rd and 4th dim of b2;

b2[1][1][0]=b[0][0];//cannot assign
Here you can assign only a 1d array to b2.But an element of 2d array is being assigned.hence not possible.

b2[1][2][0]=b;//cannot assign.
Here a 1d array should be assigned not a 2d array.

b2[0][1][0][0]=b[0][0];//can assign.
here 2d array element is being assigned to 4d array element.

b2[0][1]=big;//can assign
same as b2[0][1]=b;

I understood it better.I am not so sure that I have given you an explanation in the way you can understand.
hope this helps!
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661

I got your explanation..
And it Helped!!
I agree. Here's the link:
subject: Multi-dim Array
jQuery in Action, 3rd edition