Ruby Basic Exercises: Create a new string from a given string where the first and last characters have been exchanged
Ruby Basic: Exercise-15 with Solution
Write a Ruby program to create a new string from a given string where the first and last characters have been exchanged.
def front_back(txt) txt[-1] << txt[1...-1] << txt end print front_back("Python"),"\n" print front_back("Java"),"\n"
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program which accept the radius of the sphere as input and compute the volume.
Next: Write a Ruby program to test whether you are minor (Consider a child unless he or she is less than 18 years old.) or not.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework