multi-dimensional array challenge – convert all rows to columns and columns to rows using Java


Welcome to the Practice House, In this post, we are going to solve a problem or a challenge for multi-dimensional Array. it’s called Convert All Rows to Columns and Columns to Rows.

So what is the multi-dimensional Array? To learn more about array and multidimensional array you may google it a bit. This challenge I got from HackerEarth while studying about Data Structure.

So our Scenario will be

sample input and output for multidimensional array



We will have to create a 2D array and our task is to convert all rows to columns and columns to rows.
The first line contains 2 integers, N – total rows, M – total columns. here we got 3 rows and 5 columns.

Print  5 rows and 3 columns value as shown above image.

Okay Now let’s check our my solutions how i did it.

Our Code Snippet :


Our Console Output:

Here I showed the example with 3 rows and 5 columns so I needed to key in 15 values. You can try with small values.


Congratulations we have made it. So we learned how to take input and how to create the array and then we convert that array in a new array. That’s great, isn’t it? Let me know your thought about this problem. The source code will be available in my Github. So feel free check it out and improve it.

Thank you so much for visiting us.

Leave a Reply

Notify of