Wave print row wise

#include
using namespace std;

int main() {
int n,m;
cin>>n;
cin>>m;
int arr[n][m];
for(int i=0; i<n; i++){
for( int j=0;j<n;j++){
cin>>arr[i][j];
}
cout<<endl;
}
for(int row=0; row<n; row++){
if(row%2==0){
for(int col=0; col<n;col++){
cout<<arr[row][col]<<’,’<<’ β€˜;
}
}
else{
for(int col=m-1; col>=0;col–){
cout<<arr[row][col]<<’,’<<’ ';
}
}
}
cout<<β€œEND”<<endl;
return 0;
}
//getting the exact output still test cases not successful

hi @srivastavaayush1611_3fd51b257da0b834 updated

//CODE IN JAVA BUT IT IS SHOWING RUN-TIME ERROR IN COMPILER!!! WHAT TO DO??

import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int M = scn.nextInt();
int N = scn.nextInt();
int[][] mat = new int[M][N];
int c1 = 0;
while (c1 < mat.length) {
int r1 = 0;
while (r1 < mat[0].length) {
mat[c1][r1] = scn.nextInt();
r1++;
}
c1++;
}

	print(mat);

}


public static void print(int[][] mat) {
	int c = 0;
	while (c < mat.length) {
		int r = 0;
		while (r < mat[0].length) {
			if (c % 2 == 0) {
				System.out.print(mat[c][r] + ", ");
			} else {
				int ntp = 0;
				ntp = mat.length - r - 1; // used to ulta print odd column
				System.out.print(mat[c][ntp] + ", ");
			}
			r++;

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

}