1
1

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.

Rubyで1行で複数データを入力し、文字列から数値に変換、数値から文字列に変換する方法

Posted at
line = gets.chomp.split
#文字列から数値に変換
a = line[0].to_i
b = line[1].to_i
P = a - b
Q = a * b
#数値から文字列に変換
puts P.to_s + " " + Q.to_s

Rubyでは
to_i ・・・文字列データから数値データに変換
to_s ・・・数値データから文字列データに変換
になります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?