···
public class RoundArray {
public static void main(String[] args) {
// int[][] array = {
// { 1, 2, 3 , 11, 15 },
// { 4, 5, 6, 21, 25 },
// { 7, 8, 9, 31 , 35},
// { 41, 42, 43, 44, 45 },
// { 51, 52, 53, 54, 55 }
// };
int[][] array = {{1}};
printAttay(array);
}
private static void printAttay(int[][] array) {
if (array == null) {
return;
}
int n = array[0].length;
int quareCounts = n / 2 + n % 2;
for (int quareIndex = 0; quareIndex < quareCounts; quareIndex++) {
for (int topRow = quareIndex; topRow < n - quareIndex; topRow++) {
System.out.println(array[quareIndex][topRow]);
}
for (int rightCol = quareIndex + 1; rightCol < n - quareIndex; rightCol++) {
// n-1,
System.out.println(array[rightCol][n - quareIndex - 1]);
}
for (int bottomRow = n - quareIndex - 2; bottomRow > quareIndex; bottomRow--) {
System.out.println(array[n - quareIndex - 1][bottomRow]);
}
for (int leftCol = n - quareIndex - 1; leftCol > quareIndex; leftCol--) {
System.out.println(array[leftCol][quareIndex]);
}
}
}
}
···