Ruby Basic Exercises: Check whether a string starts with 'if'
Write a Ruby program to check whether a string starts with "if".
Ruby Code:
def start_if(str)
return str[0, 2] == "if";
end
print start_if("ifelse"),"\n"
print start_if("endif"),"\n"
Output:
true false
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program which accept the radius of a circle from the user and compute the parameter and area.
Next: Write a Ruby program which accept the user's first and last name and print them in reverse order with a space between them.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics