2020-10-16から1日間の記事一覧
任意の文字列で"hi"がいくつあるか数えてその数を出力するメソッドを作ります。 出力例: count_hi('abc hi ho') → 1count_hi('ABChi hi') → 2count_hi('hihi') → 2 def cunt_hi(str) puts str.scan("hi").length end puts "hiの数は" hi = gets.to_s cunt_h…
任意の文字列で"hi"がいくつあるか数えてその数を出力するメソッドを作ります。 出力例: count_hi('abc hi ho') → 1count_hi('ABChi hi') → 2count_hi('hihi') → 2 def cunt_hi(str) puts str.scan("hi").length end puts "hiの数は" hi = gets.to_s cunt_h…