File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array confusion

 
a alph
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is from K&B book.



which of the following codes could be inserted at line 7, and still allow the code to compile? (choose four).

a) b2 [0][1] = b;
b) b [0][0] = b3;
c) b2 [1][1][0] = b [0][0];
d) b2 [1][2][0] = b;
e) b2 [0][1][0][0] = b [0][0];
f) b2 [0][1] = big;

I couldn't understand how to work it out the dimensions.
Can anyone please help.

Thanks.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just need to make sure that the reference types are the same in the LHS and RHS:


And to elaborate:

byte[][][][] b;
Now, b is a 4-dimensional byte array.
This means:
b[0] will be a 3-dimensional byte array, or a reference of type byte[][][]
b[0][0] will be a 2-dimensional byte array, or a reference of type byte[][]
b[0][0][0] will be a 1-dimensional byte array, or a reference of type byte[]
b[0][0][0][0] will be a reference of type byte (you can think of it as a 0-dimensional byte array)
 
a alph
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ruben for your very clear explanation.

Regards
alph
 
Ruben Soto
Ranch Hand
Posts: 1032
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic