2
0

More than 3 years have passed since last update.

Array クラスの select メソッド

Posted at

RubyのArrayクラスのSelectメソッドの使い方
Rubyで入力した値のうち、3の倍数のデータをa配列に追加して、a配列に入っている要素数をカウントするRubyプログラムです

n = gets.to_i
a = gets.split(' ').select { |n| n.to_i % 3 == 0 }

puts a.length

この方法は知らなかったので勉強をかねてQiitaブログに掲載いたします。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0