logo CodeStepByStep logo

rowColumnConvert

Language/Type: Java string parameters return
Related Links:

Write a method named rowColumnConvert that accepts a string and an integer representing a number of rows as parameters and returns a new string as follows. Think of the string's characters being displayed downward in columns in the given number of rows. For example, the call of rowColumnConvert("ABCDEFGHIJKLMN", 3) would think of the characters of the string as being placed into 3 rows as follows:

      column
row 1 2 3 4 5
 1  A D G J M
 2  B E H K N
 3  C F I L

Your function should reorder the letters to be read left-to-right in row-major order, so this call would return "ADGJMBEHKNCFIL". Notice that the string's length may not be an exact multiple of the number of rows, such as column 5 in our example containing only "MN". If the number of rows is 0 or less, return an empty string.

You should not need to use any auxiliary collections (array, list, map) to solve this problem.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.