String Quiz

str = "string"

puts str[-1] # .............. A
puts str[5] # ............... B
puts str[str.length - 1] # .. C
puts str[0..4] # ............ D

Which of the above expressions will print "g"?

A B C D
str = "string"

puts str[2, 3] # ... A
puts str[2..3] # ... B
puts str[3, 2] # ... C
puts str[3..4] # ... D

Which of the above expressions will print the same slice of "string"?

A & B A & C B & C C & D
name = "Sabine"

puts 'Hello ' + name + ', how are you today?' # ... A
puts "Hello " + name + ", how are you today?" # ... B
puts 'Hello #{name}, how are you today?' # ........ C
puts "Hello #{name}, how are you today?" # ........ D

Which of the above expressions will print identical strings?

A B C D

results matching ""

    No results matching ""