我制作了这个程序,它计算你名字中的字符。
puts 'What is your first name?'
forename = gets.chomp
puts 'what is your middle name?'
middlename = gets.chomp
puts 'what is your surname?'
surname = gets.chomp
puts 'Did you know there are ' + forename.length.to_s + middlename.length.to_s + surname.length.to_s + ' characters in your name?'
但是,这将彼此相邻的数字相加等于 555 而不是 15。我无法将长度转换为整数,因为我之前无法添加文本字符串。