Forums Register Login

Doubt in Multi D Array-Qs 12 Pg 49, K&B

+Pie Number of slices to send: Send
Hi Ranchers....am preparing for SCJP 1.4 and not getting through this question. Please help me out.
Given the following,
1. public class Test {
2. public static void main(String [] args) {
3. byte [][] big = new byte [7][7];
4. byte [][] b = new byte [2][1];
5. byte b3 = 5;
6. byte b2 [][][][] = new byte [2][3][1][2];
7.
8. }
9. }
which of the following lines of code could be inserted at line 7, and still allow the code to
compile? (Choose four that would work.)


Please do let me know about the approach to go for.
Thanks
+Pie Number of slices to send: Send
First of all kirti, welcome to JavaRanch.

Please let us know the options that we are being asked to choose from.

Thanks
-Barry


(Barry:edited out my mistake - question source in title)
[ February 05, 2007: Message edited by: Barry Gaunt ]
+Pie Number of slices to send: Send
Hi Barry.
Below are the options to choose from.



Given the following,
1. public class Test {
2. public static void main(String [] args) {
3. byte [][] big = new byte [7][7];
4. byte [][] b = new byte [2][1];
5. byte b3 = 5;
6. byte b2 [][][][] = new byte [2][3][1][2];
7.
8. }
9. }
which of the following lines of code could be inserted at line 7, and still allow the code to
compile? (Choose four that would work.)
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;

Please let me know about thge soln.
thanks
+Pie Number of slices to send: Send
Hi,
Correct ans: A,B,E,F

Check for the correct dimentions we can assign, means 2d -> 2d, 3d -> 3d, etc...in C & D, assignment is not compatible as dimentions are not same.

Hope this helps.

Regards.
+Pie Number of slices to send: Send
Thanks Nirav.....but still how could you find E?? I am not getting it.....Please help.

Regards
Kirti
+Pie Number of slices to send: Send
Hi,

b2[0][1][0][0] is the single element value of 4d array. And b[0][0] is also the element value of 2d array. So E is also one of the correct answer.

Regards,
Paras
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 845 times.
Similar Threads
Self Test Question on Arrays by Kathy's Book
Array confusion
Multidimensional Arrays
Can you tell me how to answer such question?
multidimensional array question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:23:05.