Write a static method called encode that takes a string s and an integer n as...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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). 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).
Expert Answer:
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
Write a recursive method called countBinary that accepts an integer n as a parameter and that prints all binary numbers that have exactly n digits in ascending order, each on its own line. All digits...
-
Write a recursive method called doubleDigits that accepts an integer n as a parameter and returns the integer obtained by replacing every digit of with two of that digit. For example,...
-
Write a static method called "acronym" that takes as a parameter a String containing a phrase and that returns an acronym for the phrase. For example, the following call: acronym("self contained...
-
Assume a companys estimated sales is 27,000 units. Its desired ending finished goods inventory is 5,000 units, and its beginning finished goods inventory is 3,000 units. What is the required...
-
1. Find the initial temperature of a 49.0-N cube of zinc, 16.0 cm on a side that gives off 3.36 x 105 J of heat while cooling to 80.0C. 2. A coolant lowers the temperature 13C in a steel engine...
-
The formation of a buffer solution is an example of the common-ion effect. Explain how a buffer works with reference to a solution containing acetic acid and sodium acetate.
-
The case study can be completed without GST or with GST using either the rates for Australia or New Zealand. Inventory can be accounted for using either the periodic or the perpetual method. We have...
-
The Chester's workforce complement will grow by 10% (rounded to the nearest person) next year. Ignoring downsizing from automating, what would their total recruiting cost be? Assume Chester spends...
-
A ( n ) _ _ _ _ _ _ _ _ _ _ contains a specific piece of information within a record. Field Entity Row Database
-
Robert A. Kliesh, age 41, is single and has no dependents. Robert's Social Security number is 111-11-1111. His address is 201 Front Street, Missoula, MT 59812. He is independently wealthy as a result...
-
An income property for sale is expected to generate NOI of $100,000 in the 1st year, increasing by 3% per year. An investor is considering buying it for a 5-yearholding period. The investor is...
-
Partial adjusted trial balance data for Parsons Company is presented in BE3-9. The balance in Common Stock is the balance as of January 1. Prepare a retained earnings statement for the year assuming...
-
Which of the following is not a reason why a single set of high-quality international accounting standards would be beneficial? (a) Mergers and acquisition activity. (b) Financial markets. (c)...
-
Each business transaction must have a dual effect on the accounting equation. For example, if an individual asset increases, there must be a corresponding (1) decrease in another asset, or (2)...
-
Sketch the ROC of a non-causal system whose T.F. is given as \[ H(s)=\frac{(s+2)(s-2)}{s(s+1)(s-3)} \] Mark the poles and zeros of \(H(s)\).
-
(a) The system requires memory and so it is dynamic. (b) The output depends on present and past inputs. Hence, it is causal. (c) The output due to the delayed input is same as the delayed output. The...
-
Siran borrowed money from Chauncey and agreed to pay back $1,200 4 months from now and $1,700 in 7 months. If Siran is unable to make these payments and instead wants to pay back the loan completely...
-
A 20-cm-square vertical plate is heated to a temperature of 30oC and submerged in glycerin at 10oC. Calculate the heat lost from both sides of the plate.
-
Convert the following iterative method into a recursive method: // Returns n!, such as 5! = 1*2*3*4 *5 %3D public static int factorial (int n) { int product 1; for (int i = 1; i
-
For the next four problems, consider the task of representing types of tickets to campus events. Each ticket has a unique number and a price. There are three types of tickets: walk-up tickets,...
-
Which of the following statements about min-heaps is true? a. Smaller values are on the left and larger values are on the right. b. The smallest value is the root. c. The smallest value is one of the...
-
Each second, the burning Suns mass (a) increases. (b) remains unchanged. (c) decreases.
-
The Sun contains what percentage of the solar systems mass? (a) about 35% (b) 85% (c) the percentage varies over time (d) over 99%
-
Asteroids orbit (a) the Moon. (b) Earth. (c) the Sun. (d) all of these (e) none of these
Study smarter with the SolutionInn App