LoginSignup
11
6

More than 5 years have passed since last update.

Ruby 複数行の入力を受け取る 改行なしで受け取る

Posted at

複数行の入力を受け取る

input = readlines

# 入力
# 120
# 115
# 122
# 116
# 119
# 117

print input 
# 出力結果
# ["120\n", "115\n", "122\n", "116\n", "119\n", "117 "]

puts input
# 出力結果
# 120
# 115
# 122
# 116
# 119
# 117 

複数行の入力を改行なしで受け取る

input = readlines.map &:chomp

# 入力
# 120
# 115
# 122
# 116
# 119
# 117

print input 
# 出力結果
# ["120", "115", "122", "116", "119", "117"]

puts input
# 出力結果
# 120
# 115
# 122
# 116
# 119
11
6
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
11
6