目前正在研究Ruby中的HackerRank问题。当我尝试编译:字符串不能被强制转换为Fixnum(TypeError)
in `+': String can't be coerced into Fixnum (TypeError)
以下行
print d + double
我不理解,因为没有这两个变量是一个字符串。
i = 4
d = 4.0
s = 'HackerRank'
# Declare second integer, double, and String variables.
intOne = 12
double = 4.0
string = "is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!"
# Read and save an integer, double, and String to your variables.
intOne = gets.chomp
double = gets.chomp
string = gets.chomp
# Print the sum of both integer variables on a new line.
print i + intOne
# Print the sum of the double variables on a new line.
print d + double
# Concatenate and print the String variables on a new line
print s + string
# The 's' variable above should be printed first.
5行,你分配一个'String'它。所以,当然,这是一个'字符串'! –