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

  • برمجة روبي
  • برمجة

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.

الأجوبة

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
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...