I have a program, called Three.java, here's how it runs. 

I compile it, I run it with a command line argument. 

It generates the magic square of that size and then it checks it. 

It reports if it's a magic square or not (it always is, as it should). 

-bash-4.1$ javac Three.java
-bash-4.1$ java Three 3
   4   9   2
   3   5   7
   8   1   6
true
-bash-4.1$ java Three 5
  11  18  25   2   9
  10  12  19  21   3
   4   6  13  20  22
  23   5   7  14  16
  17  24   1   8  15
true
-bash-4.1$ java Three 7
  22  31  40  49   2  11  20
  21  23  32  41  43   3  12
  13  15  24  33  42  44   4
   5  14  16  25  34  36  45
  46   6   8  17  26  35  37
  38  47   7   9  18  27  29
  30  39  48   1  10  19  28
true
-bash-4.1$ java Three 9
  37  48  59  70  81   2  13  24  35
  36  38  49  60  71  73   3  14  25
  26  28  39  50  61  72  74   4  15
  16  27  29  40  51  62  64  75   5
   6  17  19  30  41  52  63  65  76
  77   7  18  20  31  42  53  55  66
  67  78   8  10  21  32  43  54  56
  57  68  79   9  11  22  33  44  46
  47  58  69  80   1  12  23  34  45
true
-bash-4.1$ java Three 13
  79  94 109 124 139 154 169   2  17  32  47  62  77
  78  80  95 110 125 140 155 157   3  18  33  48  63
  64  66  81  96 111 126 141 156 158   4  19  34  49
  50  65  67  82  97 112 127 142 144 159   5  20  35
  36  51  53  68  83  98 113 128 143 145 160   6  21
  22  37  52  54  69  84  99 114 129 131 146 161   7
   8  23  38  40  55  70  85 100 115 130 132 147 162
 163   9  24  39  41  56  71  86 101 116 118 133 148
 149 164  10  25  27  42  57  72  87 102 117 119 134
 135 150 165  11  26  28  43  58  73  88 103 105 120
 121 136 151 166  12  14  29  44  59  74  89 104 106
 107 122 137 152 167  13  15  30  45  60  75  90  92
  93 108 123 138 153 168   1  16  31  46  61  76  91
true
-bash-4.1$

--