Write a Ruby program to check Palindrome Number
class PalindromeNumber
def checkPalindrom
print "Enter the number: "
input_num = gets.chomp.to_i
num = input_num
new_num = 0
while num > 0 do
rem = num % 10
num = num / 10
new_num = (new_num * 10) + rem
end
if input_num == new_num
print "#{input_num} is a palindrome number"
else
print "#{input_num} is not a palindrome number"
end
end
end
p = PalindromeNumber.new
p.checkPalindrom
Output:
Enter the number: 1221
1221 is a palindrome number
|
No comments:
Post a Comment