output seems to be correct but throwing wrong testcases
package challenges;
import java.util.Scanner;
public class Waveprintcolumnwise {
static Scanner scan=new Scanner(System.in);
public static void main(String[] args) {
int M=scan.nextInt();
int N=scan.nextInt();
if(M<=10&&N<=10)
{
displayarray(M,N);
}
}
public static void displayarray(int rows,int cols)
{
int j=0;
int [][] array=new int[rows][];
for(int row=0;row<array.length;row++)
{
array[row]=new int[cols];
for(int col=0;col<array[row].length;col++)
{
array[row][col]=scan.nextInt();
}
}
for(;j<=array.length-1;)
{
if(j%2==0)
{
int i=0;
for(;i<=array.length-1;)
{
System.out.print(array[i][j]+", ");
i++;
}
}
else
{
int i=array.length-1;
for(;i>=0;i--)
{
System.out.print(array[i][j]+", ");
}
}
j++;
}
System.out.println("END");
}
}