Cloumn Wave all test case failed after compiling correct

It gives the correct output when compile but throwing error while submitting

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

	int[][] arr = new int[m][n];
	
	for (int i = 0; i < m; i++) {
		
		for (int j = 0; j < n; j++) {
			arr[i][j] = s.nextInt();
		}
		
	}
	
	for (int i = 0; i < m; i++) {
		if(i % 2 == 0) {
			for (int j = 0; j < n; j++) {
				System.out.print(arr[j][i] + ", ");
			}
		}else {
			for(int j = n-1; j >= 0; j--) {
				System.out.print(arr[j][i] + ", ");
			}
		}
	}
	System.out.println("END");

Hey @danyalkhan8271 Very sorry for the late reply but I was not feeling well. So The problem with your code is : in the part below you need to change i with j and j with i bcoz you are using ar[j][i] but constraints given to i are of rows but you have sent it in the place of columns.so swap i and j in the this part;
for (int i = 0; i < m; i++) {

if(i % 2 == 0) {

for (int j = 0; j < n; j++) {

            System.out.print(arr[i][j] + ", ");

}

}else {

for(int j = n-1; j >= 0; j–) {

            System.out.print(arr[i][j] + ", ");

}

}

}

if i swap i with j in this part it will not print the same pattern, as given in question…

@danyalkhan8271 Yeah and that means you need to change your logic a little bit.

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.