id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > dec15_2016_APSLHL_letterSpread
prev  |  next  |  chance

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)

public String dec15_2016_APSLHL_letterSpread(String str, int toAdd, char ltr) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 240

Copyright Nick Parlante 2017 - privacy