Q:

Write a Ruby program to check whether a given array of integers of length 2 contains a 4 or a 7

0

Write a Ruby program to check whether a given array of integers of length 2 contains a 4 or a 7.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_array(nums)
    if(nums[0] == 4 || nums[0] == 7)
		return true
	end	
	return (nums[1] == 4 || nums[1] == 7)
end

print check_array([1, 4]),"\n" 
print check_array([7, 5]),"\n"   
print check_array([5, 2])  

Output:

true
true
false

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now