Skip to content

Instantly share code, notes, and snippets.

@trevorlang94
Created April 23, 2017 03:10
Show Gist options
  • Save trevorlang94/78d02958501ee2e36653c0f39b85d743 to your computer and use it in GitHub Desktop.
Save trevorlang94/78d02958501ee2e36653c0f39b85d743 to your computer and use it in GitHub Desktop.
ruby file
index = 0
numbers = Array.new
negatives = Array.new
positives = Array.new
puts "Enter a list of numbers here, one line at a time.\n When you are finished entering your numbers, either press ctrl+z and hit enter, or manually enter ^z\n and then hit the enter key."
while (number = gets.to_i)
numbers[index] = number
index += 1
end
for i in 1...numbers.length do
if numbers[i] > 0
positives.push(numbers[i])
elsif numbers[i] < 0
negatives.push(numbers[i])
end
end
puts "Displaying positive numbers you have entered: \n"
puts positives
puts "\nDisplaying negative numbers you have entered: \n"
puts negatives
C:/Users/Main/Documents/SERVER-SIDETEMP/numbers.rb:10:in `gets': Interrupt
from C:/Users/Main/Documents/SERVER-SIDETEMP/numbers.rb:10:in `gets'
from C:/Users/Main/Documents/SERVER-SIDETEMP/numbers.rb:10:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment