Ruby Basic Exercises: Check whether a string starts with 'if'
Ruby Basic: Exercise-5 with Solution
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?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/ruby-exercises/basic/ruby-basic-exercise-5.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics