Showing posts with label palindrome in ruby. Show all posts
Showing posts with label palindrome in ruby. Show all posts

Thursday, October 20, 2016

Palindrome in Ruby

Here is a simple program that I wrote in Ruby programming language that will ask the user to give a string or a word and then our program will check if the given word or a string is a palindrome or not a palindrome. We can called a word a palindrome if we read the word forward and backward the spelling and the sound is the same. I hope you will find my work useful. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 


My mobile number here in the Philippines is 09173084360.


Program Listing

palindrome.rb

def check_palindrome(str)
  if str.reverse == str
    puts "\n\n";
    puts "The given word #{str} is a palindrome."
puts "\n";
  else
puts "\n";
    puts "The given word #{str} isn't a palindrome."
puts "\n";
  end
end

loop do
print "\n\n";
print "Palindrome Program"
print "\n\n";
print "Enter a String : ";
str_test = gets.chomp
check_palindrome(str_test.upcase)
puts "\n";
print "Do you want to continue? (y/n) : "
  answer = gets.chomp.downcase
  if answer == "n"
print "\n\n";
    print "End of Program";
    print "\n\n";
break
  end
end