💡 Arrays-Wave print Column Wise

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");


}

}

hi @Pradeep
there was just one mistake …


instead of writing array.length, you shud have initialized as array[0].length … because we are accessing the columns and not rows on j’s values

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.