I'm trying to get multiple inputs and assign it to different variables (in the irb) but I can't seem to get it to work. I'm only able to do it for the first variable, but for the next three, the last input gets assigned to the other 2 (I have 4 in all)
What I'm trying to do is, based on the first input (say, 2), it'll prompt for 3 more inputs 2 times.
t = gets.to_i
This is the first input and it gets assigned properly. It'll then prompt for 3 more inputs, but then only the last input gets saved and is assigned to all three variables.
a = gets.to_i
b = gets.to_i
k = gets.to_i
it'll accept 3 inputs but only the last gets saved?
say if I enter (for the first iteration)
1
10
3
after the first prompt (which i entered 2) a, b, and k has value 3
t = gets.to_i
a = b = k = []
for i in 0..t-1 do
a[i] = gets.to_i
b[i] = gets.to_i
k[i] = gets.to_i
end
Is it because it's in a loop? I'm putting it there since it has to ask for the values of a, b and k for t times where t is the first input.
I'm not sure if I explained it properly but I hope someone can understand what I was trying to do
[]) or by calling one of theArrayfactory methods (e.g.Array::[]orArray::new). Count the number of calls to factory methods and count the number of array literals in your code.