• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array JavaKara, inverting and flipping horizontally a grid  RSS feed

 
Filipe Madureira
Ranch Hand
Posts: 44
1
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again guys

I'm using JavaKara (a graphic Java software to learn coding) on my classes at the moment and we're asked to transform something like this:




in the inverse, where you can see clovers there must not be any and where there aren't you must plant them. PLUS YOU MUST SWITCH THE FIGURE HORIZONTALLY.

This is the result i should obtain:





Unfortunately i have NO IDEA on how to switch everything horizontally!

This is my result:



I know that you guys probably never used JavaKara so you have no idea about the methods and stuff, i just hope you understand.
So, my ultimate question is, how do i have to edit the second loop, and why, to obtain the horizontally reversed result i'm supposed to obtain?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it have to be done in one loop? It could be, i think the code would be easier to read if you handle the problems separately. You have already done the inversion. Good job!

Can you write nested loops that go through all the rows (outer loop) and half the columns (inner loop). Then inside the loop, swap the two entries. Hint: swapping two things requires three lines of code
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that Java does not have truly multi-dimensional arrays. In reality, they are just nested arrays. With a 2-level nesting it depends on your X-Y representation: you may need nested for-loops where you are switching elements or you may need only one for-loop where you are switching entire arrays.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!