RB
rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def is_palindrome(value) value.downcase!
# Reverse the string
reversed = ""
count = value.length
while count > 0
count -= 1
reversed += value[count]
end # Instead of writing codes for reverse string
# we can also use reverse ruby method
# something like this value == value.reverse
if value == reversed
return "#{value} is a palindrom :>"
else
return "#{value} is not a palindrom :/"
end
end
puts "Enter a Word"
puts " "
puts "what is palindrom ?"
puts "a palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or hannah. Sentence-length palindromes may be written when allowances are made for adjustments to capital letters, punctuation, and word dividers "
puts "-------------------------------"
a = gets.chomp
p is_palindrome(a)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run