File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Moving Diagonally in a 2D array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Moving Diagonally in a 2D array" Watch "Moving Diagonally in a 2D array" New topic
Author

Moving Diagonally in a 2D array

Vincent Mule
Greenhorn

Joined: Oct 04, 2012
Posts: 14
So for example I have an array like this

100
0-10
000

and I want to move between the -1 and the 1. Lets say that coord[0] is my current row and coord[1] is my current column. How do I craft a statement that would allow me to move in between those numbers?


Edit, I figured it out.

for example, moving down and left, its arr[current number+1][current number+1]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30378
    
150

Vincent Mule wrote:
and I want to move between the -1 and the 1. Lets say that coord[0] is my current row and coord[1] is my current column.

This doesn't match your example. Suppose you are in the upper left corner. Your row is coord[0] and your cell is coord[0][0]. It doesn't make sense to talk about the column alone since you can't reference it alone. (I'm harping on this because I think it is easier to understand as I stated it.)

Now what cell do you want to end up in when you move diagonally? What do you need to coord[x][y] to make that happen?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Moving Diagonally in a 2D array