Ruby Basic Exercises: Check two non-negative integer values and return true if they have the same last digit
Ruby Basic: Exercise-30 with Solution
Write a Ruby program to check two non-negative integer values and return true if they have the same last digit.
Sample array : ["Ruby", 2.3, Time.now]
Ruby Code:
def test_last_digit(a, b)
return (a % 10 == b % 10);
end
print test_last_digit(5, 5),"\n"
print test_last_digit(15, 25),"\n"
print test_last_digit(256, 346),"\n"
print test_last_digit(26, 34)
Output:
true true true false
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to print the elements of a given array.
Next: Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- 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
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework