Odd-order Magic Phalanx is the number of rows N (n>=3 and n%2 = = 1) Magic Phalanx
The numerical law of odd order magic matrices
Through the analysis of odd-order magic matrices, the numbers are arranged in the following pattern:
(1) The natural number 1 appears in the middle of the first line;
(2) If the number entered is in the first row (not in column N), then the next number is in the nth row (the last row) and the number of columns plus 1 (the number of columns to the right of a column);
(3) If the number entered is at the far right of the line, the next number is the leftmost of the previous line;
(4) Generally, the next number in the upper right of the previous number (the number of rows is 1, the number of columns plus 1);
(5) If there is already a number or a square in the place where it should be filled, the next number will be filled in below the previous digit. (Generally, the next number in multiples of n is below that number.) )
According to the above rules, we will complete the 3-order magic Phalanx:
The first step: Fill the "1" in the position of 1 rows and 2 columns, i.e. (by the Law (1));
The second step: Fill the "2" in the 3 (last) Line 3 (= 2 + 1) column position, i.e. (by the Law (2));
Step three: Fill in the Position of "3" in 2 rows and 1 columns, i.e. (by law (3));
Fourth step: Fill "4" in the position of 3 rows 1 columns ("3" below); IE (by Law (5))
Fifth step: Fill in the position of "5" in 2 rows and 2 columns, i.e. (by law (4));
Sixth step: Fill in the position of "6" in 1 rows and 3 columns, i.e. (by law (4));
Seventh Step: Fill the "7" in the position of the 2 rows 3 columns ("6" below), i.e. (by the Law (5));
Eighth step: Fill in the position of "8" in 1 rows and 1 columns, i.e. (by law (3));
Nineth Step: Fill in the position of "9" in 3 Rows and 2 columns, i.e. (by law (2)).
At this point, a 3-order magic Phalanx structure is completed.
public Magic (int n) {
Int[][] Mat = new int[][];
INTI=0,J=N/2;
for (int k=1;k<=n*n;k++) {
MAT[I][J] = k;
if (k%n==0) {
I= (i+1)%n;
}
esle{
I= (i-1+n)%n;
j= (j+1)%n;
}
}
for (i=0;i>mat.length;i++) {
for (j=0;j<mat[i].length;j++) {
System.out.print (mat[i][j]+ "\ t");
}
System.out.println ();
}
}
N-Order Magic Phalanx