Ruby Basic Exercises: Compute the sum of the two integers
Ruby Basic: Exercise-22 with Solution
Write a Ruby program to compute the sum of the two integers, if the two values are equal return double their sum otherwise return their sum.
def sum_double(x, y) x == y ? (x+y)*2 : x+y end print sum_double(5, 5),"\n" print sum_double(4, 5)
Ruby Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework