class Noname2
{
public static void main(String[] args)
{
int SIZE = 5;
int arr[][] = new int[SIZE][SIZE];
int i, j, k = 0, n, m;
n = SIZE;
m = (n + 1) / 2;
for (i = 0; i < n; i++)
{
for (j = i; j <= n - i - 1; j++)
arr[i][j] = ++k;
for (j = i + 1; j <= n - i - 1; j++)
arr[j][n - i - 1] = ++k;
for (j = n - i - 2; j >= i; j--)
arr[n - i - 1][j] = ++k;
for (j = n - i - 2; j >= i + 1; j--)
arr[j][i] = ++k;
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
System.out.print(arr[i][j] + "\t");
System.out.println("");
}
}
}
|