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

 

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

Write a method that helps two characters "time travel" to new locations in a string. Find the first occurance of 'first' and the last occurance of 'last'. Return a new string where these two characters have been swapped. For example: drWhoCharacterTimeTravel("This is a test",'i','t') will result in "Thts is a tesi". If either 'first' or 'last' does not occur in the string, then just return the original string unchanged.


drWhoLetterTimeTravel("I am The Doctor", "o", "m") → "I ao The Dmctor"
drWhoLetterTimeTravel("But it has always made that noise. I LIKE that noise.", "i", "n") → "But nt has always made that noise. I LIKE that ioise."
drWhoLetterTimeTravel("tardis blue", "e", "a") → "terdis blua"

...Save, Compile, Run (ctrl-enter)

public String drWhoLetterTimeTravel(String str, char first, char last) { }

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: 290

Copyright Nick Parlante 2017 - privacy