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

 

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

Write a method that swaps each adjacent character in a string and returns the result. For example, the string "1234567" becomes "2143657". The string "1234" becomes "2143". Notice that the swapping starts at the beginning of the string and continues as long as there is a pair of characters left to swap. If there are an odd number of characters, the last one does not have a "buddy" to swap with, so it just gets placed at the end. Look at the test data for additional examples.


nov4_2016_SLHL_swapEveryOther("Lenore") → "eLoner"
nov4_2016_SLHL_swapEveryOther("The Raven") → "hT eaRevn"
nov4_2016_SLHL_swapEveryOther("books") → "obkos"

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

public String nov4_2016_SLHL_swapEveryOther(String str1) { }

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