我是 Ruby 编程的初学者。我的程序是计算给定字符串中偶数长度的单词数。但它显示以下错误
[0, 0] :Array 的未定义方法“<”
这是我的代码
def even(words, n)
i = 0, m = 0
while i < n do
count = count + words[i].length
if count%2 == 0 then
m = m + 1
end
i = i + 1
end
return m
end
prinnt "Enter The String:"
s = gets.chomp
words = s.split()
n = words.length
x = even(words, n)
puts x
最佳答案
我认为你的问题出在这里
i = 0, m = 0
成功了
i = 0
m = 0
编辑:
也像Kai König说的,如果你这么叫它就意味着
" now's the time".split #=> ["now's", "the", "time"]
关于ruby-on-rails - [0, 0] :Array <NoMethodError> 的未定义方法 '<',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11499850/