#!/usr/bin/env ruby
def factor(number, number1)
remainder = number % number1
print "The remainder is #{remainder}"
if remainder == 0
puts "#{number} is a factor of #{number1}"
else
puts "#{number} is not a factor of #{number1}"
end
end
puts
print "Enter the number : "
number=gets.chomp
print "Enter the number to check for its factor : "
number1=gets.chomp
factor(number,number1)
$end
答案 0 :(得分:0)
在将 gets.chomp 调用数字时应该转换输入字符串,然后像这样调用方法。
puts
print "Enter the number : "
number=gets.chomp.to_i
print "Enter the number to check for its factor : "
number1=gets.chomp.to_i
factor(number,number1)