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