Ruby String Exercises: Sort a string's characters alphabetically
Write a Ruby program to sort a string's characters alphabetically.
Ruby Code:
def check_string(str)
return str.chars.sort.join
end
print check_string("javascript")
print "\n",check_string("python")
print "\n",check_string("PHP")
Output:
aacijprstv hnopty HPP
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to count the occurrences of a specified character in a given string.
Next: Write a Ruby program to remove a specified character into a given string.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics