This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays" Watch "Arrays" New topic


Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
This is a quesetion from Whizlabs.

I have no clue about the answer
(I even doubt if even one of the options is correct!)

Which code initializes the two-dimensional array tab so that tab

[3][2] is a valid element?

int[][] tab= { {0,0,0},{0,0,0}};

A. int tab[][] = { 0,0,0,0

B. int tab[][]=new tab[4][];
for (int i=0;int[3]) tab[3][2];

D. int[] tab[]={ {0,0,0},{0,0,0},{0,0,0},{0,0,0}}

Can some help me understand Multidemnsional array and how i can see them in a pictorial form.

Like I know arr[3][4] would mean 3 rows and 4 colums, but what about arrays like arr[3][4][5] and how i would initializee them or know that hte initialisation is correct.

The future belongs to those who believe in the beauty of their dreams.Dream BIG!
vidhya suvarna
Ranch Hand

Joined: Aug 28, 2008
Posts: 148
i think option B & D are correct..
But didnt get the for statement in option B
i.e for (int i=0;int[3])..

can you please confirm this..

SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
I don't have the right answer and for some reason i also feel that the B statement is incomplete.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

only D is correct. B is syntactically wrong. In case of D you are creating a 2-d array in which there is an element that can be referenced as tab[3][2]. Don't be confused with the declaration int[] tab[]. It is the same as int[][] tab or int []tab[].........

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
vidhya suvarna
Ranch Hand

Joined: Aug 28, 2008
Posts: 148
is B wrong because we have it as int tab[][]=new tab[4][]; where we are sure of 4 rows and not about how many columns..right?

Joined: Sep 08, 2008
Posts: 10
no B is wrong bcause of the incomplete for syntax
it should be for(< initialization >;<boolean expression>;< loop statement > {}
I agree. Here's the link:
subject: Arrays
Similar Threads
Array Basics
accessing 2 dimensional array...
K&B SCJP 5 Study Guide p628 problem 9
how to use array in array?
Dimensional Travel