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

【初歩中の初歩】Rubyで掛け算をしてみよう★

Posted at

今回はRubyを使って掛け算をしてみます。

問題:2つの正の整数a, bが改行区切りで入力されるのでaとbを掛け算した数値を出力してください。

解答

解答コード
a = gets.to_i
b = gets.to_i

puts a*b

解説

解説
a = gets.to_i

to._iでaの保存形式をinteger型にしています。
これによって、puts a*bで数値の計算が行われることになります。

解説

解説
puts a*b

putsメソッドによって実際に出力を行います。
Rubyでは「*」が「×(かける)」の意味を持ちます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?