目前正在研究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'它。所以,當然,這是一個'字符串'! –