1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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ブログに掲載いたします。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?