def count_vowels(string)
vowels = ["a", "e", "i", "o", "u"]
i = 0
j = 0
count = 0
while i < string.length do
while j < vowels.length do
if string[i] == vowels[j]
count += 1
break
end
j += 1
end
i += 1
end
puts count
end
Run Code Online (Sandbox Code Playgroud)
我无法发现出错的地方.如果该程序遇到辅音,它就会停止.另外,使用".each"方法如何解决同样的问题?