我的代码如下。如果我删除了最后一个end
,它说unexpected end of input
,如果我放end
回去,它说unexpected keyword end
。我看不到以下代码有什么问题。你能?
n = gets.chomp.to_i
array= Array.new(n, true)
while p<Math::sqrt(n) do
i=p
while (i<=n) do
array[i] = false # not a prime
i+=p
end
while array[p]!=true do
p++
end
end
增量运算符(++
):
p++
在Ruby中不存在。你的意思是:
p += 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句