Reversing a string We can print the reverse a given number by below ways By .reverse predefined method puts "Enter the String:" puts "The reverse of #{str1} is #{str1.reverse}" Output Enter the String: By loop puts "Enter the String:" newstr= ' ' for i in 1..str1.length puts "The reverse of #{str1} is #{newstr}" Output Enter the String:
str1=gets.chomp
ruby
The reverse of ruby is ybur
str1=gets.chomp
newstr+=str1[str1.length - i]
end
ruby
The reverse of ruby is ybur
How to shuffle an array in Ruby?
How to add/remove elements to Array in Ruby?
Ruby program to add two integer numbers
Ruby program to print Fibonacci series
Program to Print Triangle of Numbers in Ruby
how to create an array with Array.[](*args) in Ruby ?
Ruby program to check whether the given number is palindrome
What's the difference between a lambda, a block and a proc?
How to get index of array element in Ruby
Ruby program to generate random numbers
Ruby program to check whether the given number is Armstrong
What are #method_missing and #send? Why are they useful?
How to Sort Array in Ruby?
Ruby program to print an array
What are the various Ruby runtimes, and how are they different?
What are some of your favorite gems? What are their alternatives?
Ruby program to reverse a string
Ruby program to check whether the given number is prime or not
How to Replace array elements in Ruby?
How to Get Input with Gets in Ruby
Ruby program to Calculate the factorial of given number
Creating Array with Array.new(size, obj) in Ruby
How to create two dimensional array in ruby?