title: I want to swap items in the diagonals of a matrix in a custom matrix class
body: <p>I want to create a method that can swap items in the diagonals of a matrix in my custom matrix class.</p>
  
  <p>If this is the input:</p>
  
  <pre><code>1,0,0,5
  0,2,6,0
  0,7,3,0
  8,0,0,4
  </code></pre>
  
  <p>This would be the output:</p>
  
  <pre><code>4,0,0,8
  0,3,7,0
  0,6,2,0
  5,0,0,1
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>import java.util.*;
  public class Matrix
  {
  public final static int MAX_INTEGER = 50;
      public final static int MAX_SIZE = 20;
  
      private int[][] matrix;
  
  
      public Matrix(int[][] matrix)
      {
          if (matrix.length &gt;= 0 &amp;&amp; matrix.length &lt;= MAX_SIZE)
              this.matrix = matrix;
          else if (matrix.length &lt; 0)
              throw new RuntimeException("The length of the array can not be negative");
          else
              throw new RuntimeException("The length of the array can not be greater than 20");
  
          Random generator = new Random();
  
          for (int i=0; i &lt; matrix.length; i++)
              for (int j=0; j &lt; matrix.length; j++)
                  matrix[i][j] = generator.nextInt(MAX_INTEGER)+1;
      }
  
  
      public void swapDiagonals()
      {   
          int aux=0;
  
  
          for (int i=0; i &lt; matrix.length; i++)
              for (int j=0; j &lt; matrix.length; j++)
                  if(i == j)
                  {                 
                      aux = matrix[i][j];
                      matrix[i][j] = matrix[matrix.length-1-i][matrix.length-1-j];
                      matrix[matrix.length-1-i][matrix.length-1-j] = aux;
                  }
  
          for (int i=0; i &lt; matrix.length; i++)
              for (int j=0; j &lt; matrix.length; j++)
                  if(i == matrix.length-j)
                  {   
                      aux = matrix[i][matrix.length-1-j];
                      matrix[i][matrix.length-1-j] = matrix[matrix.length-1-i][j];
                      matrix[matrix.length-1-i][j] = aux;
                  }    
  
  
      }
  </code></pre>
  
  <p>The thing is that the method doesn't do anything. If I check the matrix after I run the method, nothing has changed.            </p>
  
  <p>This should be a succesful outcome:</p>
  
  <pre><code>    @Test
      public void testSwapDiagonals()
      {
          Matrix dummy = new Matrix(new int[4][4]);
          assertEquals(int[][]={{13,15,23,6},{17,37,15,6},{10,7,48,45},{4,47,41,21}}, dummy.getMatrix());
          dummy.swapDiagonals();
          assertEquals(int[][]={{21,15,23,4},{17,48,7,6},{10,15,37,45},{6,47,41,13}}, dummy.getMatrix());
      }
  </code></pre>
  
  <p>Sorry, I should have been more specific: I don't want to swap all diagonals. I want <a href="https://gyazo.com/df41914bb15c853e59718e43496c122b" rel="nofollow noreferrer">this</a></p>