Program to print 2-D array wave(column wise)

// am not able to find error with this code, none of the test cases are running.
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();
int[][] arr=new int[10][10];
if(n<=10 && n>0 && m<=10 && m>0)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
arr[i][j]=sc.nextInt();
}
}
for(int i=0;i<n;i++)
{
if(i%2==0)
{
for(int j=0;j<m;j++)
{
System.out.print(arr[j][i]+", “);
}
}
else
{
for(int j=m-1;j>=0;j–)
{
System.out.print(arr[j][i]+”, “);
}
}
}
System.out.print(” END");
}

}

}

@PankajMishra,
Sample test case:
2 6
1 2 3 4 5 6
7 8 9 10 11 12

Correct Output:
1, 7, 8, 2, 3, 9, 10, 4, 5, 11, 12, 6, END

Your Output:
1, 3, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 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.