- import java.io.*;
 
 - public class copydemo {
 
  
-         /**
 
 -          * @param args
 
 -          */
 
 -         public static void main(String[] args)throws IOException
 
 -         {
 
 -                 // TODO Auto-generated method stub
 
 -                 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 
 -                 
 
 -                 while(true)
 
 -                 {        String str=br.readLine();
 
 -                         int n=Integer.parseInt(str);
 
 -                                         
 
 -                         if(n<=1){
 
 -                                 break;
 
 -                         }
 
 -                         int[][] arr=new int[n][n];
 
 -                         int temp=1;
 
 -                         int count=0;
 
 -                 
 
 -                         for(int yi=count,er=n-1;yi<=er;yi++,er--)
 
 -                                 {        
 
 -                                         for(int h=yi,l=er,a=0,z=yi;a<(er-yi);z++,temp++,a++)
 
 -                                                 {
 
 -                                                         arr[h][z]=temp;
 
 -                                                         arr[z][l]=temp+er-yi;
 
 -                                                         arr[n-h-1][n-z-1]=temp+2*(er-yi);
 
 -                                                         arr[n-z-1][h]=temp+3*(er-yi);
 
 -                                                         
 
 -                                                 }
 
 -                                                 temp=arr[yi+1][yi]+1;
 
 -                                                 
 
 -                                                 count++;
 
 -                                 }
 
 -                         if(n%2==1)
 
 -                                 arr[(n-1)/2][(n-1)/2]=n*n;
 
 -                         
 
 -                         for(int a=0;a<n;a++){
 
 -                                 for(int b=0;b<n;b++){
 
 -                                         System.out.print(arr[a][b]+"\t");
 
 -                                         }
 
 -                                 System.out.println();
 
 -                                 System.out.println();
 
 -                         }
 
 -                         
 
 -                         
 
 -                 
 
 -                 }
 
 -                 
 
 -                 br.close();
 
 -         }
 
 -         
 
 - }
 
 
  复制代码 |