w3resource

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 Array Exercises: 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:

Flowchart: Check whether an given array of integers of length 2 does not contain a 6 or a 9

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?



Follow us on Facebook and Twitter for latest update.