Here again same case

import java.util.*;
public class Main {
public static void main(String args[]) {
int k;
int n;
int m;
int a[][];
int l;
Scanner s=new Scanner(System.in);
m=s.nextInt();
n=s.nextInt();
a=new int[m][n];
for(k=0;k<m;k++){
for(l=0;l<n;l++){
a[k][l]=s.nextInt();
}
}
int row=a.length;
int col=a[0].length;
for(int i=0;i<col;i++){
if(i%2==0){
for(int j=0;j<row;j++){
System.out.print(a[i][j]+", β€œ);
}
}
else
{
for(int j=row-1;j>=0;j–){
System.out.print(a[i][j]+”, β€œ);
}
}
}
System.out.print(β€œEND”+” ");
s.close();
}
}
output is correct but this time every test case is showing run error

Hey @ketushubham098,
Please use the online IDE to share the code as the code isn’t formatted properly on this platform.

You are using the wrong variables in the for loops.
The outer for loop should be row as we are traversing row wise and then for each row we are printing the elements present in the columns alternating from left to right.
Here’s the updated code for your reference.

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.