public static void prints(int i, int n) {
int[][] arr = new int[n][n];
int num = i;
int top = 0, bottom = n - 1, left = 0, right = n - 1;
while (top = bottom && left = right) {
for (int col = left; col = right; col++) {
arr[top][col] = num;
num++;
}
top++;
for (int row = top; row = bottom; row++) {
arr[row][right] = num;
num++;
}
right--;
if (top = bottom) {
for (int col = right; col = left; col--) {
arr[bottom][col] = num;
num++;
}
bottom--;
}
if (left = right) {
for (int row = bottom; row = top; row--) {
arr[row][left] = num;
num++;
}
left++;
}
}
for (int row = 0; row n; row++) {
for (int col = 0; col n; col++) {
System.out.printf("%4d", arr[row][col]);
}
System.out.println();
}
}
INPUT Prints(1,5)