Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

RUBY: Write one Ruby program to do all. Use a ruby class string 1. Read an input

ID: 3775728 • Letter: R

Question

RUBY: Write one Ruby program to do all. Use a ruby class string 1. Read an input string - Print result (The input string) Then Find the length of the input string. - Print result 3. Display string from backward. - Print result 4. Count number of words in string. - Print result 5. Input another string. - Print result (The second input string) 6. Concatenate the second string to the first string – Print result 7. Compare the two strings they are exact equal or not. - Print result 8. Check if the first string is palindrome or not. - Print result 9. Extract the substring of 5 characters anywhere within the first string - Print result 10. Reverse the first string. Print result 11. Convert the first string to all lowercase. - Print result 12. Convert the first string to all uppercase. - Print result.

Explanation / Answer

puts "Enter string1 : "
str1 = gets.chomp
puts "Entered string : " , str1
puts "Length of string :" , str1.length
puts "Reverse of entered string", str1.reverse
puts "No.of words in string", str1.split(' ').length

puts "Enter string 2 : "
str2 = gets.chomp
puts "is two strings equal", str1 == str2

puts "string 1 is polindrom or not : ", str1.reverse == str1

puts "5 characters substring", str1[1..5]

puts "Revers of first string : ", str1.reverse

puts "Uppercase of first string : ", str1.upcase

puts "Lowercase of second string :", str2.downcase