Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a static method called encode that takes a string s and an integer n as parameters and that returns a new string that
Write a static method called encode that takes a string s and an integer n as parameters and that returns a new string that scrambles the order of the characters from s in a particular way. Taking the characters from s in order, imagine filling a grid of n rows column by column. When s is "abcdefghijklmnopqrstuvwxyz" and n is 3, you get: row 1: row 2: row 3: adgjmpsvy behknqtwz cfilorux The method should return the result of concatenating these characters together with row 1 first, then row 2, and then row 3. Notice that the final column will not necessarily be complete, as in the example above where the final column has only two characters. So if you make the call: encode ("abcdefghijklmnopqrstuvwxyz", 3) You should get back the string "adgjmpsvybehknqtwzcfilorux". The string might contain any characters, including spaces. For example, the call: encode ("four score and seven", 4) returns "f rneosedvuc eroasn" because the following grid would be produced: row 1: f rne osedv row 2: uc e roasn row 3: row 4: You may assume that the string passed as a parameter is not empty and that the integer passed as a parameter is greater than or equal to 1 and less than the length of the string. You are not allowed to construct any structured objects other than strings to solve this problem (no list, list of lists, etc).
Step by Step Solution
★★★★★
3.30 Rating (150 Votes )
There are 3 Steps involved in it
Step: 1
The detailed ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started