0
0

More than 3 years have passed since last update.

メモ

Last updated at Posted at 2020-06-01

偶数か奇数か

puts "数字入れて"
n = gets.to_i

if n.even?
 puts "偶数です"
else n.odd?
  puts "奇数です"
end  

to_i to_s

  • to_iメソッドが文字→数値
  • to_sメソッドが数値→文字

getsは文字列で保存する。
数値に変換するため→gets.to_i

each_with_index

fruits=[“りんご”, “メロン”, “イチゴ”]

fruits.each_with_index do |fruit, i|
puts “#{i+1}番目の要素は#{fruit}です。”
end
【結果】
1番目の要素はりんごです。
2番目の要素はメロンです。
3番目の要素はイチゴです。

未コミットの変更を引き継ぎつつブランチを変更する

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