Q:

Write a Ruby program to create a new string from a given string where the first and last characters have been exchanged

0

 Write a Ruby program to create a new string from a given string where the first and last characters have been exchanged. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now