A matrix with square diagonals and transpose being increments of other
Throwing a different spin on the process, I think you are missing an alternate algorithm that produces the same result....

Here is a 'simple' loop that 'works'. It works because it uses a different 'rule' that is based on the pattern that your matrix creates.

The Pattern is obvious when you study the matrix from the bottom-right corner, and work backwards. The initial value is the square of the matrix size. Then you subtract 1 to the left, then another 1 above, and another 1 to the next left, and another 1 to the next above, etc.

private static final int[][] buildMagicMatrix(int size) {
    int value = size * size + 1;
    int[][] matrix = new int[size][size];
    for (int i = size - 1; i &gt;= 0; i--) {
        matrix[i][i] = --value;
        for (int d = i - 1; d &gt;= 0; d--) {
            matrix[i][d] = --value;
            matrix[d][i] = --value;
        }
    }
    return matrix;
}


Using this algorithm you produce results like:


Size 9
    1    2    5   10   17   26   37   50   65
    3    4    7   12   19   28   39   52   67
    6    8    9   14   21   30   41   54   69
   11   13   15   16   23   32   43   56   71
   18   20   22   24   25   34   45   58   73
   27   29   31   33   35   36   47   60   75
   38   40   42   44   46   48   49   62   77
   51   53   55   57   59   61   63   64   79
   66   68   70   72   74   76   78   80   81