• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Arrays

 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
0,0,0,0,
0,0,0,0,
0,0,0,0
};


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


C.int 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.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have the right answer and for some reason i also feel that the B statement is incomplete.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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[].........
 
vidhya suvarna
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankit,
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?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no B is wrong bcause of the incomplete for syntax
it should be for(< initialization >;<boolean expression>;< loop statement > {}
 
This tiny ad is suggesting that maybe she should go play in traffic.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic