Array spiral print

test case 2 is incorrect while i have written the same code as told in video
my code is

static Scanner scn=new Scanner(System.in);
public static void main(String[] args) {
int[][]array=input();
spiralprint(array);

}

private static int[][] input() {
	int rows = scn.nextInt();
	int cols = scn.nextInt();
	int arr[][]=new int[rows][cols];
			for (int row = 0; row < rows; row++) {

for(int col=0;col<cols;col++) {
arr[row][col]=scn.nextInt();
}
}
return arr;
}
private static void spiralprint(int[][]arr) {
int top=0,bottom=arr.length-1,left=0,right=(arr[top].length)-1,count=(bottom+1)*(right+1),dir=1;
while((top<=bottom)&&(left<=right)) {
if(count>0) {
if(dir==1) {
for(int i=left;i<=right;i++) {
System.out.print(arr[top][i]+", ");
count++;
}
top++;
dir=2;
}

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

	
	
Please tell about it