My ouput is coming right still all testcases failed

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 = null;
	
	if ((M > 1 && N > 1) && (M < 10 && N < 10)) {
		arr = new int[M][N];

		for (int row = 0; row < arr.length; row++) {
			for (int col = 0; col < N; col++) {
				arr[row][col] = sc.nextInt();
			}
		}
       int col = 0;
	for (; col <= arr.length - 1;) {
		if (col % 2 == 0) {
			int row = 0;

			for (; row <= arr.length - 1;) {
				System.out.print(arr[row][col] + ", ");
				row++;
			}
		} else {
			int row = arr.length - 1;
			for (; row >= 0; row--) {
				System.out.print(arr[row][col] + ", ");
			}
		}

		col++;

	}

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

}

pls help me im waiting

hey @nigamshubham1998 Your code is not working for n!=m
just a change
int col = 0;
for (; col <= arr[0].length - 1; ) {


you can see this

can you tell me what is the meaning of arr[0].length in this for loop for (int col = 0; col < arr[0].length; col++)

rest of all i got the mistake

length of col of array arr is arr[0].length;