Code work prefect but error in submission time

check the code please

@deepgarg46 There a small mistake here in the for loop of line no. 18 it should be arr[0].length not arrr.length bcoz arr.length will give no. of rows but here you want no. of columns.
Corrected code :

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m =sc.nextInt();
		int[][] arr = new int[n][m];
		for(int i = 0;i<n;i++) {
			for(int j=0;j<arr[i].length;j++) {
				arr[i][j]=sc.nextInt();
			}
		}
		WavePrint(arr);
	}

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

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

}
1 Like

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.