title: Rotate matrix in place
body: <p>I'm solving the <strong>rotate an NxN matrix in place</strong> question.  </p>
  
  <p>It seems that my code makes a rotation, but leaves an X over the image.<br>
  So I'm guessing it's rotating the edges incorrectly.
  I'm attaching two images as sample input and output.</p>
  
  <p><img src="https://i.stack.imgur.com/8VEJc.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/9b9TX.png" alt="enter image description here"></p>
  
  <p>What's wrong with my code:</p>
  
  <pre><code>public static void rotateRight(float[][] img){
      for (int i=0; i&lt;N/2; i++){
          for (int j=i; j&lt;N-i; j++){
              int J_COMP = N-j-1; //complement of J
              int LEFT = i;
              int RIGHT = N-i-1;
              int TOP = i;
              int BOTTOM = N-i-1;
  
              float temp = img[J_COMP][LEFT];
              img[J_COMP][LEFT] = img[BOTTOM][J_COMP];
              img[BOTTOM][J_COMP] = img[j][RIGHT];
              img[j][RIGHT] = img[TOP][j];
              img[TOP][j] = temp;
          }
      }       
  }
  </code></pre>