• 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
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Question on multi dimensional array

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code


The o/p when u compile the above code is

b2[0][0][0][0] 1
b2[0][0][0][1] 2
b2[0][1][0][0] 0
b2[0][1][0][1] 0
b2[0][2][0][0] 0
b2[0][2][0][1] 0
b2[1][0][0][0] 0
b2[1][0][0][1] 0
b2[1][1][0][0] 0
b2[1][1][0][1] 0
b2[1][2][0][0] 0
b2[1][2][0][1] 0
2
ia[0][0]1
ia[0][1]0

In the above code ,the line b2[0][0]=b; assigns byte values 1,2 of b[][] array to b2[][][][] array.
But I wanna assign byte values 3,4 of b[][] array to b2[][][][] array.I am unable to do it....Can anybody try the code & tell me how to do it?
Thanks
Veena
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Veena,
I'm not sure that I understand your question, but it sounds like you are saying that you can not access all of the elements of array b after it is assigned to array b2. In other words, it sounds like you can not access all of the elements of array b using the reference b2. I have not tried to run the code, but I think that your declaration of b2 is the problem. While the dimensions of array b are 2 X 2, the dimensions of array b2 are 2 X 3 X 1 X 2. You might have more luck accessing b[1][0] and b[1][2] using the reference b2 if array b2 were declared as a 2 X 3 X 2 X 2 array.
I hope that I correctly understood your question.
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan,
I am sorry if my question was not clear.In the above code byte values 1,2 of b array are assigned to b2 array.What should I do to assign byte values 3,4 of b array to b2 array.The above code produces following o/p.
b2[0][0][0][0] 1
b2[0][0][0][1] 2
b2[0][1][0][0] 0
b2[0][1][0][1] 0
b2[0][2][0][0] 0
b2[0][2][0][1] 0
b2[1][0][0][0] 0
b2[1][0][0][1] 0
b2[1][1][0][0] 0
b2[1][1][0][1] 0
b2[1][2][0][0] 0
b2[1][2][0][1] 0
2
ia[0][0]1
ia[0][1]0
What changes I should make in the above code to get the following o/p
b2[0][0][0][0] 3
b2[0][0][0][1] 4
b2[0][1][0][0] 0
b2[0][1][0][1] 0
b2[0][2][0][0] 0
b2[0][2][0][1] 0
b2[1][0][0][0] 0
b2[1][0][0][1] 0
b2[1][1][0][0] 0
b2[1][1][0][1] 0
b2[1][2][0][0] 0
b2[1][2][0][1] 0
2
ia[0][0]1
ia[0][1]0
I hope I made my doubt clear.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Veena Point:

What changes I should make in the above code to get the following o/p
b2[0][0][0][0] 3
b2[0][0][0][1] 4


I have not tried to run the code, but my assumptions are as follows.
The values 3 and 4 are stored at
b2[0][0][1][0] 3
b2[0][0][1][1] 4
Since you have declared b2 as
byte b2[][][][]=new byte[2][3][1][2];
you won't have access to the elements where 3 and 4 are stored. You could solve the access problem by defining b2 as follows.
byte b2[][][][]=new byte[2][3][2][2];
If you want the declaration of b2 to remain unchanged and if you don't need access to the first two elements of b then you could try the following new assignment statement.
b2[0][0][0]=b[1];
As I mentioned earlier, I have not tried the code but I think that it will work.
I wish you luck.
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dan Chisholm:

If you want the declaration of b2 to remain unchanged and if you don't need access to the first two elements of b then you could try the following new assignment statement.
b2[0][0][0]=b[1];


Wow!It worked out.Thank you Dan.You really think very deep.This multi dimensional array problem was bugging me from many days.Now it is clear.Thanks alot.
Veena
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic