ruby 代碼
- words = 'Learning Ruby - Your one stop guide'
- puts words.split(" ").reverse.join(" ")
- # guide stop one Your - Ruby Learning
如果反轉中文字呢?
2,判斷閏年
ruby 代碼
- puts "請輸入一個年份,我來判斷是否是閏年:"
- year=gets.chomp.to_i
- leap = case
- when year % 400 == 0: true
- when year % 100 == 0: false
- else year % 4 == 0
- end
- var="不" unless leap
- puts "#{year}"+"#{var}"+"是閏年"