0
0

More than 1 year has passed since last update.

Rubyの入力と出力メソッド

Last updated at Posted at 2020-11-22

ruby 2.7.0についての記事です。

Rubyの入力メソッドのまとめ

1.gets
getsメソッドを使って入力した値は全て文字列になる
公式ドキュメント(IOクラスgets)

【関連するメソッド】

num = gets.split # "10 100"と入力します
print num #=> ["10", "100"]
print num[0] #=> 10
print num[1] #=> 100

answer = num[0].to_i * num[1].to_i # 整数に変換します
print answer #=> 1000

Rubyの出力メソッドのまとめ

num = gets.split # "10 100"と入力します
puts num #=>
10
100
puts num[0] #=> 10
puts num[1] #=> 100

answer = num[0].to_i * num[1].to_i # 整数に変換します
puts answer #=> 1000

puts "hello"
puts "world" #=>
hello
world

print "hello"
print "world"
#=> helloworld

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