We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello there, I'm trying to save inside a 2d array some coordinates of the the processing frame. For instance: I have my array of int positions[][] and I would like to initialize it with my values(75,300,525) (75,300,525). and the scan through them while I need it with a nested loop. In fact the point I need are:75-75,75-30,75-525 and so on.. So for example:
positions[0][0]={{75},{75}}
positions[0][1]={{75},{300}}
positions[0][2]={{75},{525}}
but unfortunately it doesn't work. When I print the values it's completely messed up and I get values like this:[I@1de498 [I@8ae45a
I know it could be done easily using 2 single arrays one for the X and another for the Y. but honestly I woud like to understand better this 2d arrays.
Thank you guys.
Answers
this is defining an array containing two arrays each containing a single number. what you're seeing when you print it out is a reference to the array objects.
positions[0][0] = 75;
positions[0][1] = 75;
or
positions[0] = {75, 75};
is, i think, what you want (untested)
or even
again, untested
Thanks guys! I understand what was the problem. I think I was doing right except for a couple of things: While I was testing I used this code to control the flow: println(position[0][0] + " " +i); i was increased by a for cycle. That line doesn't work for some reasons.
and refers accordingly to: 0-0/1
1-0/1
2-0/1
I think that the main problem was that sort of mistake in the println which drove me into the wrong way... thank you guys!
Besides this at-once format:
We can assign a sub-array 1 by 1 to it: (~~)