Q:

Write a Ruby program to create a new string from a given string with the last character added at the front and back of the given string

0

Write a Ruby program to create a new string from a given string with the last character added at the front and back of the given string. The lenght of the given string must be 1 or more.

All Answers

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

def temp(str)
    len = str.length() - 1;
	return (str.split('')[len] + str + str.split('')[len]);
end

print temp("abc"),"\n"
print temp("abcd"),"\n"
print temp("java")

Output:

cabcc
dabcdd
ajavaa

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