Arrays: Spiral Print Clockwise

I paste my code below, it is working for test case and also in my IDE for different cases, so I cant understand why is it failing test cases here. Please help me in resolving it:

import java.util.*;
public class Main {
public static void main(String args[]) {

	Scanner sc = new Scanner(System.in);
	int m = sc.nextInt();
	int n = sc.nextInt();

	int[][] arr = new int[m][n];

	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			arr[i][j] = sc.nextInt();
		}
	}

	int top = 0,bottom =m-1,right = n-1,left = 0,i=0,j=0,count=0;

	while(count<m*n){

			for(j=left;j<right;j++){
				System.out.print(arr[top][j] + ", ");
				count++;
			}
			
			for(i=top;i<bottom;i++){
				System.out.print(arr[i][right]+", ");
				count++;
			}
			
			for(j=right;j>0;j--){
				System.out.print(arr[bottom][j]+", ");
				count++;
			}

			for(i=bottom;i>0;i--){
				if(count==m*n){
					System.out.print("END");
					break;
				} 
				System.out.print(arr[i][left]+", ");
				count++;
			}
			
			top++;
			bottom--;
			right--;
			left++;
		

		
	}

	
}

}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

I can see your comment Sir, but I am unable to find the answer for the doubt, please guide me where to visit?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.