What is the problem rises

import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int rows = scn.nextInt();
int cols = scn.nextInt();
int[][] arr = new int[rows][cols];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = scn.nextInt();
}
}
spiralprint(arr);

}

private static void spiralprint(int[][] arr) {
	int top = 0;
	int bottom = arr.length - 1;
	int dir = 2;
	int count = (bottom + 1) * (bottom + 1);
	while (top <= bottom) {

		if (count > 0) {
			if (dir == 2) {
				for (int i = 0; i <= bottom; i++) {
					System.out.print(arr[i][top] + ", ");
					count--;
				}
				dir = 4;
			}
			top += 1;
		}

		if (count > 0) {
			if (dir == 4) {
				for (int i = bottom; i >= 0; i--) {
					System.out.print(arr[i][top] + ", ");
					count--;
				}
				dir = 2;
			}
			top += 1;
		}

	}
	System.out.println("END");

}

}

@Harsh_Sonwani,
Wrong answer for the input:
2 3
1 2 3
4 5 6
Expected Output:
1, 4, 5, 2, 3, 6, END

Your output:
1, 4, 5, 2, END

CAN U CORRECT MY CODE

Sir I got my code. thnx for this help.