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 get index of array element in Ruby
Ruby program to add two integer numbers
What are #method_missing and #send? Why are they useful?
What are some of your favorite gems? What are their alternatives?
Ruby program to reverse a string
Ruby program to generate random numbers
How to Get Input with Gets in Ruby
How to Sort Array in Ruby?
Ruby program to print Fibonacci series
What's the difference between a lambda, a block and a proc?
Ruby program to check whether the given number is Armstrong
How to Replace array elements in Ruby?
Ruby program to check whether the given number is palindrome
Ruby program to print an array
How to add/remove elements to Array in Ruby?
Creating Array with Array.new(size, obj) in Ruby
Ruby program to check whether the given number is prime or not
Ruby program to Calculate the factorial of given number
Program to Print Triangle of Numbers in Ruby
how to create an array with Array.[](*args) in Ruby ?
How to shuffle an array in Ruby?
How to create two dimensional array in ruby?
What are the various Ruby runtimes, and how are they different?