package arrays;
public class SpiralPrinting {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] a = new int[][] { { 1, 2, 3 }, { 5, 6, 7 }, { 9, 10, 11 },
{ 13, 14, 15 } };
int cols = a[0].length;
int rows = a.length;
Business1 b = new Business1();
b.print(a, rows, cols);
}
}
class Business1 {
int i = 0;
int j = 0;
int count = 0;
public void print(int[][] a, int row, int col) {
int max = row * col;
while (count < max) {
for (int k = 0; k < col; k++) {
System.out.println(a[i][j]);
j++;
count++;
}
row--;
j--;
i++;
for (int k = 0; k < row; k++) {
System.out.println(a[i][j]);
i++;
count++;
}
i--;
j--;
col--;
for (int k = 0; k < col; k++) {
System.out.println(a[i][j]);
j--;
count++;
}
row--;
j++;
i--;
for (int k = 0; k < row; k++) {
System.out.println(a[i][j]);
i--;
count++;
}
i++;
j++;
col--;
}
}
}