Ruby Array Exercises: Check whether an given array of integers of length 2 does not contain a 6 or a 9
Ruby Array: Exercise-18 with Solution
Write a Ruby program to check whether an given array of integers of length 2 does not contain a 6 or a 9.
Ruby Code:
def check_array(nums)
if(nums[0] == 6 || nums[0] == 9)
return false
end
return !(nums[1] == 6 || nums[1] == 9)
end
print check_array([1, 4]),"\n"
print check_array([6, 5]),"\n"
print check_array([5, 9])
Output:
true false false
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check whether an given array of integers of length 2 contains a 4 or a 7.
Next: Write a Ruby program to check if an given array of integers contains 3 twice, or 5 twice. The array will be length 0, 1, or 2.
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/array/ruby-array-exercise-18.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics