class LuoXuan
{
public static void main(String[] args)
{
int n=5;
int x;int y;
int arr[][]=new int [n][n];
int m=(n+1)/2;int num=1;
for (x=0;x<n ;x++ )
{
//上面;
for (y=x;y<=n-x-1 ;y++ )
{
arr[x][y]=num;
num++;
}
//右面;
for (y=x+1;y<=n-x-1 ;y++ )
{
arr[y][n-x-1]=num;
num++;
}
//下面;
for (y=n-x-2;y>=x ;y-- )
{
arr[n-x-1][y]=num;
num++;
}
//左面;
for (y=n-x-2;y>=x+1 ;y-- )
{
arr[y][x]=num;
num++;
}
}
for (x=0;x<n ;x++ )
{
for (y=0;y<n ;y++)
{
System.out.print(arr[x][y]+"\t");
}
System.out.println();
}
}
}
|
|