Write a Ruby program to create a new string from a given string where the first and last characters have been exchanged.
Ruby Code:
def front_back(txt) txt[-1] << txt[1...-1] << txt[0] end print front_back("Python"),"\n" print front_back("Java"),"\n"
Output:
nythoP aavJ.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Ruby Code:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer