w3resource

Ruby Basic Exercises: Print names in reverse order with a space between them

Ruby Basic: Exercise-6 with Solution

Write a Ruby program which accept the user's first and last name and print them in reverse order with a space between them.

Ruby Basic Exercises: Print names in reverse order with a space between them

Ruby Code:

puts "Input your first name: "
fname = gets.chomp
puts "Input your last name: "
lname = gets.chomp
puts "Hello #{lname} #{fname}"

Output:

Input your first name: 
Input your last name: 
Hello Lanoie Gary

Flowchart:

Flowchart: Print names in reverse order with a space between them

Ruby Code Editor:

Contribute your code and comments through Disqus.

p>Previous: Write a Ruby program to check if a string starts with "if".
Next: Write a Ruby program to accept a filename from the user print the extension of that.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.