• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mirroring an array  RSS feed

 
Duane Carroll
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me with this? The question being asked is to provide a method that takes a two-dimensional square array of integers as a parameter and reflects that array about a diagonal such that cell [0,0] is swapped with cell [n-1],[n-1]. For example, the array

4 8 -2 9
0 -4 3 6
3 1 -5 2
-7 6 7 -1
should become

-1 2 6 9
7 -5 3 -2
6 1 -4 8
-7 3 0 4

Thank you in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duane,
Welcome to CodeRanch!

Forget about Java/code for a minute. Can you describe how to do it in English. For example, suppose you only had to switch [0.0] with its pair. How would you do that? Then suppose you only had to switch [0,1] with its pair. How would you do that? And how would you know when you could stop looking at cells to switch.

Try replying to this post with your thoughts on this. Then we can give pointers on making it more specific or the next step.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never let anybody tell you there is such a thing as a 2D array in Java®. That is an array of arrays, which is better than a 2D array.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you swapping the places in the array, or creating a new array?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!