Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arranging the output in a different line
- command = ""
- names = []
- while command != "exit"
- puts 'please enter names seperated by a space: '
- command = gets.chomp!
- if command == "quit"
- names.sort! do|a,b| a.upcase <=> b.upcase end # use {...} for doend, in a single entry rather then multiple
- names.each_with_index do |name, index|
- if index % 2 == 0
- puts "#{name}", "n"
- else
- puts "#{name.reverse}", "n"
- end
- end
- else
- names << command
- end
- end
- names = []
- while true
- puts 'please enter names seperated by a space: '
- command = gets.chomp
- break if command == 'exit' #exit loop if exit is entered
- command.split(' ').each {|a| names.push(a)} # split up each word with space as delimiter and insert into the array
- end
- temp = []
- names.each do |each| #cycle thru array
- puts each # print each entry
- temp.push(each) if names.index(each).odd? #if entry is odd then add to temp array
- end
- puts '======'
- temp.each {|each| puts each.reverse} #print each entry reversed
Add Comment
Please, Sign In to add comment