Write a Ruby program to split number into digits
class NumberToDigits
def printNumberToDigit
print "Enter the number "
num = gets.chomp
print "Digits are: "
num.split("").each do |n|
print n+ " "
end
end
end
p = NumberToDigit.new
p.printNumberToDigits
Output:
class NumberToDigits
def printNumberToDigit
print "Enter the number "
num = gets.chomp
print "Digits are: "
num.split("").each do |n|
print n+ " "
end
end
end
p = NumberToDigit.new
p.printNumberToDigits
Output:
Enter the number 589
Digits are: 5 8 9
|
No comments:
Post a Comment