Tag: arrays都是

如何在Ruby中重新创建(每次创建新的)数组?

我错过了为每对数字创建新数组然后把每一对的总和? 顺便说一句,是否有可能通过’,’在一行输入一对数字? arr = [] sum = 0 puts “How much pair of numbers do you want to sum?” iter = gets.to_i iter.times do |n| puts “Enter pair of numbers: ” a = gets.to_i b = gets.to_i arr << a arr << b end iter.times do |n| puts "Here are the sums: " arr.each { […]