将输出排列在不同的行中
只需要进行一些润色工作..
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 do\end, 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
因此该程序的作用是显示用户输入的许多名称。我不能让它做的就是在彼此下面显示名称。例如。 抢 账单 露西 劈 ... 然后向后显示每个第二个名字,并将它们显示在像这样的
rob
bill
lucy
Chop
======
llib
pohc 下。
lolmy 脑子熟了有什么建议吗?
just a bit of polish work needed..
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 do\end, 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
so what this progam does is display a number of names that where entered by the user. what i cant get it to do is display the names under each other. eg.
rob
bill
lucy
chop
...
its then to display every second name backwards and to display them under like this
rob
bill
lucy
chop
======
llib
pohc.
lolmy brain is cooked any suggestions??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会这样做:
如果你愿意,我可以尝试修复你的......
Here is how I would do it :
I can try to fix yours if you want...