← all problems

swapEnds 🌶️🌶️

Write a method that takes one String parameter, s, and returns a new String with the first and last characters swapped, leaving everything in between exactly where it is. For example, swapEnds("cars") should return "sarc" - the "c" and "s" have traded places, and "ar" is untouched in the middle. You may assume s has at least two characters.