我是ruby的新手,我正在编写一个代码,其中我需要一个数组递减stackoverflow prob。我想乘两个数字使得乘法的结果应该是像给定的格式:使用for循环减少红宝石中的数组
325
* 4405
---------
1625
000
1300
1300
---------
1431625
这是我的代码。
a = gets.to_i
b = gets.to_i
e = b.to_s.split('')
d = a.to_s.split('')
for j in (e).downto(0)
for i in (d).downto(0)
puts w = ((e[i]).to_i)*((d[j]).to_i)
end
end
输入我给a = 325
和b = 4405
。 但我得到错误
<main>': undefined method `downto' for ["4", "4", "0","5"]:Array (NoMethodError)
你想做什么?你能否用言语形容呢? –
对不起,我试图乘以这两个数字,使乘法的结果应该如上 – user3164249