Array - wave print row wise

no error is coming giving output perfect but not passing any testcase got 0 score

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();
//2d array declaration
int [][] arr = new int[M][N];

	for(int i=0; i<=arr.length-1;i++){
		for(int j=0;j<=arr[i].length-1;j++)
		{
			arr[i][j] = sc.nextInt();
		}
	}
	display(arr);

}
public static void display(int [][] arr)
{
	for(int i=0;i<=arr.length-1;i++){
		if(i%2==0)
		{
			for(int j=0;j<=arr.length-1;j++)
			{
				System.out.print(arr[i][j]+ ", ");
			}
		}
		else
		{
			for(int j=arr.length-1;j>=0;j--)
			{
				System.out.print(arr[i][j]+ ", ");
			}
		}
	}
	System.out.print("END");
}

}

@Naman_Gupta,
https://ide.codingblocks.com/s/253066 corrected code.

The error was that the matrix is not square matrix for every test case.

An easy way to check code is to put input as:
2 3
1 2 3
4 5 6

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.