PackageCom.imooc.text;/*** Third-order Magic side 8 Results *@authorsouth of the north of Mexico **/ Public classMagic { Public Static voidMain (string[] args) {intA = 0, B = 1; Square1 (A, b); System.out.println (); Square2 (A, b); System.out.println (); A= 2; b= 1; Square3 (A, b); System.out.println (); Square4 (A, b); System.out.println (); } Public Static voidSquare1 (intIintj) {intn = 3, mat[][] =New int[N][n]; for(intK = 1; K <= n * N; k++) {Mat[i][j]=K; if(k% n = = 0) I= (i + 1)%N; Else{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]+ " "); System.out.println (); } System.out.println (); Reverse (MAT); Print1 (MAT); } Public Static voidSquare2 (intIintj) {intn = 3, mat[][] =New int[N][n]; for(intK = 1; K <= n * N; k++) {Mat[i][j]=K; if(k% n = = 0) I= (i + 1)%N; Else{i= (i-1 + N)%N; J= (j-1 + N)%N; } } for(i = 0; i < mat.length; i++) { for(j = 0; J < Mat[i].length; J + +) System.out.print (Mat[i][j]+ " "); System.out.println (); } System.out.println (); Reverse (MAT); Print1 (MAT); } Public Static voidSquare3 (intIintj) {intn = 3, mat[][] =New int[N][n]; for(intK = 1; K <= n * N; k++) {Mat[i][j]=K; if(k% n = = 0) I= (i-1 + N)%N; Else{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]+ " "); System.out.println (); } System.out.println (); Reverse (MAT); Print1 (MAT); } Public Static voidSquare4 (intIintj) {intn = 3, mat[][] =New int[N][n]; for(intK = 1; K <= n * N; k++) {Mat[i][j]=K; if(k% n = = 0) I= (i-1 + N)%N; Else{i= (i + 1 + N)%N; J= (j-1 + N)%N; } } for(i = 0; i < mat.length; i++) { for(j = 0; J < Mat[i].length; J + +) System.out.print (Mat[i][j]+ " "); System.out.println (); } System.out.println (); Reverse (MAT); Print1 (MAT); } Public Static voidReverseinttemp[][]) { for(inti = 0; i < temp.length; i++) { for(intj = i; J < Temp[i].length; J + +) { intK =Temp[i][j]; TEMP[I][J]=Temp[j][i]; Temp[j][i]=K; } } } Public Static voidPrint1 (inttemp[][]) { for(inti = 0; i < temp.length; i++) { for(intj = 0; J < Temp[i].length; J + +) {System.out.print (Temp[i][j]+ " "); } System.out.println (); } }}
8 kinds of result output of Java third-order magic square