問題1-1の答え
ruby_1.rb
puts "おはよう"
問題1-2の答え
ruby_1.rb
puts 5
puts 9 + 9
puts 6 - 7
問題1-3の答え
ruby_1.rb
puts 50 + 5
puts "66"
問題1-4の答え
ruby_1.rb
puts 5 * 4
puts 8 / 4
puts 9 % 5
問題1-5の答え
ruby_1.rb
puts "こんばんは!" + "Ruby"
問題2-1の答え
ruby_2.rb
text = "おはよう"
puts text
問題2-2-1の答え
ruby_2.rb
message = "Ruby"
puts message
text = "エンジニア"
puts message + text
問題2-2-2の答え
ruby_2.rb
num1 = 3
puts num1
num2 = 5
puts num1 + num2
問題2-3の答え
ruby_2.rb
num1 = 5
puts num1
num1 = 3
num1 = num1 - 2
puts num1
問題2-4の答え
ruby_2.rb
birthplace = "仙台"
puts "私の出身は#{birthplace}です。"
問題3-1の答え
ruby_3.rb
rain = 65
if rain > 60
puts "傘を持っていきましょう"
end
問題3-2の答え
ruby_3.rb
rain = 40
if rain > 60
puts "傘を持っていきましょう"
elsif rain >= 40
puts "傘を持って行った方がいいですね"
else
puts "傘はいりません"
end
問題3-3の答え
①
ruby_3.rb
a = "山田"
if a == "山田"
puts "私の名前は山田です。"
end
②
ruby_3.rb
b = "山田"
if b != "小松"
puts "私の名前は山田ではありません。"
end
問題4-1の答え
ruby_4.rb
countries = ["日本","アメリカ","イタリア"]
puts countries
問題4-2の答え
ruby_4.rb
countries = ["日本","アメリカ","イタリア"]
puts "私は#{countries[2]}出身です。"
問題4-3の答え
ruby_4.rb
studys = ["国語","数学","体育"]
studys.each do|study|
puts "私は#{study}が好きです"
end
問題5-1の答え
ruby_5.rb
user = {"name" => "Kida","sex" => "Man"}
puts user
問題5-2の答え
ruby_5.rb
user = {"name" => "Kida","age" => 29}
puts user
user["age"] = "二十九"
puts user
問題5-3の答え
ruby_5.rb
user = {"name" => "Kida","age" => 29}
puts user
user["sex"] = "Man"
puts user
問題6-1の答え
ruby_6.rb
user = {:name => "YAMADA", :age => 29}
puts user
問題6-2の答え
ruby_6.rb
user = {:name => "YAMADA", :age => 29, :sex => "man"}
puts user[:sex]
問題6-3の答え
ruby_6.rb
user = {name:"YAMADA", country:"JAPAN", age:29}
puts user[:country]
問題7-1の答え
ruby_7.rb
example = {name:"YAMADA"}
if example[:pref]
puts "私の名前は#{example[:name]}です。東京出身です。"
else
puts "私の名前は#{example[:name]}です。神奈川出身です。"
end
問題8-1の答え
ruby_8.rb
user = [{name:"YAMADA", age:29}, #インデックス[0]
{name:"KIDA", age:35}, #インデックス[1]
{name:"KUBO", age:19} #インデックス[2]
]
puts user[2]
問題8-2の答え
ruby_8.rb
user = [{name:"YAMADA", age:29}, #インデックス[0]
{name:"KIDA", age:35}, #インデックス[1]
{name:"KUBO", age:19} #インデックス[2]
]
puts user[0][:name]
問題8-3の答え
ruby_8.rb
users = [{name:"YAMADA", age:29},
{name:"KIDA", age:35},
{name:"KUBO", age:29}
]
users.each do |user|
puts user
end