Magic squares of odd order: Difference between revisions
Content added Content deleted
(→{{header|Java}}: added Java) |
m (→{{header|Java}}: print a little nicer) |
||
Line 604: | Line 604: | ||
public static void main(String[] args) { |
public static void main(String[] args) { |
||
int n = 5; |
int n = 5; |
||
for (int[] row : magicSquareOdd(n)) |
for (int[] row : magicSquareOdd(n)) { |
||
for (int x : row) |
|||
System.out.format("%2s ", x); |
|||
System.out.println(); |
|||
} |
|||
System.out.printf("\nMagic constant: %d ", (n * n + 1) * n / 2); |
System.out.printf("\nMagic constant: %d ", (n * n + 1) * n / 2); |
||
} |
} |
||
Line 647: | Line 650: | ||
Output: |
Output: |
||
<pre> |
<pre>17 24 1 8 15 |
||
23 5 7 14 16 |
|||
4 6 13 20 22 |
|||
10 12 19 21 3 |
|||
11 18 25 2 9 |
|||
Magic constant: 65 </pre> |
Magic constant: 65 </pre> |