Skip to content

Instantly share code, notes, and snippets.

@DavidRails
DavidRails / Ruby_hoework_1.rb
Created October 22, 2018 11:00
Ruby practice
# 練習:請印出從 1 到 100 之間所有的單數。
array_1_to_100=[*1..100]
array_1_to_100_odd=array_1_to_100.select{|a| a%2==1}
p array_1_to_100_odd
# 練習:請印出從 1 到 100 之間所有的單數的總和。
sum=0
for i in 1..100 do