Question: Write the Java method below that takes an integer array freq and a character array text . These two arrays have the same length. The
Write the Java method below that takes an integer array freq and a character array text. These two arrays have the same length. The method returns a character array that has freq[0] repetitions of the first character in the text array, then freq[1] repetitions of the next character in the text array, and so on. For example, if the arrays freq and text are as follows:
freq
| 3 | 1 | 5 | 2 |
text
| m | s | k | p |
The method would return the following array:
| m | m | m | s | k | k | k | k | k | p | p |
----------------------------------------------------------------------------------------------------------
public static char [] repeatChars(int [] freq, char [] text) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
