【发布时间】:2016-09-16 05:04:14
【问题描述】:
我是在 Stackoverflow 上发帖的新手,但我在搞清楚一些事情时遇到了很多麻烦。我是红宝石语言的新手。
我想计算数组中某个元素大于特定常数的次数。数组长度在 10 到 25 之间,由用户选择。然后我将数组从大到小排序。我想计算数组中某个值大于或等于 35 的次数。这将定义为常量“配额”
puts "Enter a number between 10 and 25 to represent the number of users: "
num = gets.to_i
if num > 25 or num < 10
puts "I said between 10 and 25. Try again"
num = gets.to_i
end
homeDir = Array.new(num) { rand(20..50)}
homeDir.sort!{|x,y| y<=>x}
puts homeDir
quota = 35
【问题讨论】:
标签: arrays ruby count scripting