// 魔術方塊 import java.io.*; public class a13 { public static void main(String args[]) throws Exception { //程式進入點 String getbr; int i,j,scale,cnt; int x_pt,y_pt,nx_pt,ny_pt; int matrix[][]=new int [15][15]; BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); while (true) { for (i=0;i<15;i++) for (j=0;j<15;j++) matrix[i][j]=0; do { System.out.print("請輸入奇數階數:"); getbr = br.readLine(); if (getbr.equals("0")) //判斷結束 { System.out.println("結束!"); return; } scale=Integer.parseInt(getbr); if ((scale%2)==0 ) //長度超過或不足 { System.out.println("請輸入奇數!"); } else if ( scale<0 || scale>15) System.out.println("輸入數字長度不對請重新輸入"); } while ( (scale%2)==0 || scale<0 || scale>15); y_pt=0; x_pt=scale/2; cnt=scale*scale; //System.out.println(scale + " "+cnt); for (i=1;i<=cnt;i=i+1) { matrix[y_pt][x_pt]=i; //System.out.println(y_pt + " "+x_pt+"="+i); ny_pt=(y_pt+scale-1)%scale; nx_pt=(x_pt+1)%scale; while (matrix[ny_pt][nx_pt]!=0 && i