about | help | code help+videos | done | prefs |
Write a method that "spreads" a string by inserting 'toAdd' number of the single-character string 'ltr' between each character. Note that there will be no 'ltr' added before the first character or after the last character in the string. The only string methods you may use are .length, .charAt, .substring, .equals, and .compareTo (although these are not all needed!) Preconditions: 'str' may be any string; 'toAdd' will be non-negative, 'ltr' will be a single-character string which could contain any character except the escape character. dec15_2016_APSLHL_letterSpread("hello", 0, "X") → "hello" dec15_2016_APSLHL_letterSpread("testing", 2, " ") → "t e s t i n g" dec15_2016_APSLHL_letterSpread("run", 1, "X") → "rXuXn" ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 240
Copyright Nick Parlante 2017 - privacy