Ruby program to convert full name into initials



Write a Ruby program to convert full name into initials

Example.

Enter your name
Umesh kumar kushwaha
Initials are U.K.K.


class FullNameToInitials
  def fullNameToInitials
    print "Enter the name: "
    name = gets.chomp
    initial_name = ""
    name.split.each do |n|
      initial_name = initial_name +  n[0].upcase + "."
    end 
    puts "Initial name is: #{initial_name}"
  end
end

p = FullNameToInitials.new 
p.fullNameToInitials

Output:

Enter the name:  Umesh kumar kushwaha
Initial name is: U.K.K.


No comments:

Post a Comment