ray*_*ray 2 ruby arrays sorting
我正在尝试对数组进行排序,但它总是返回相同的原始输入.你知道为什么吗?
puts "Please tell me the array(separated by space, finish by enter twice):"
x = []
input = ' '
while input != ''
input = gets.chomp
x.push input
end
puts x.sort
Run Code Online (Sandbox Code Playgroud)
您需要split
输入和concat
单个数组:
x = [ ]
loop do
input = gets.chomp
break if (input.empty?)
x += input.split
end
puts x.sort
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
280 次 |
最近记录: |