Ruby 字符串回文判断

2015-01-14 0 531
Ruby 字符串回文判断
def is_palindrome(word)
  if word == word.reverse
   "#{ word } is a palindrome."
  else
   "#{ word } is not a palindrome."
 end
end

# Example implementation:
puts is_palindrome("racecar") 
# This would return "racecar is a palindrome."
puts is_palindrome("penis")
# This would return "penis is not a palindrome."

遇见资源网 ruby Ruby 字符串回文判断 http://www.ox520.com/16234.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务