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

 

test2020_10_15_APP1SLHL_swap


Write a method that swaps the first and last 'swapNum' number of characters of the input parameter string 'str'. For example, if str="swap these" and swapNum=2 you would return "seap thesw" (because you swapped the first and last two characters. As a precondition, you may assume that swapNum will be less than or equal to half the length of str and that str will have at least two characters.


test2020_10_15_APP1SLHL_swap("abcdefghijklmnop", 3) → "nopdefghijklmabc"
test2020_10_15_APP1SLHL_swap("abcdefghijklmnop", 5) → "lmnopfghijkabcde"
test2020_10_15_APP1SLHL_swap("xyz", 1) → "zyx"

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

public String test2020_10_15_APP1SLHL_swap(String str, int swapNum) { }

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