Q:

Write a Ruby program to check whether a given array of integers contains 3 twice, or 5 twice. The array will be length 0, 1, or 2

0

Write a Ruby program to check whether a given array of integers contains 3 twice, or 5 twice. The array will be length 0, 1, or 2

All Answers

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

def check_array(nums)
    if(nums.length == 2)
        if(nums[0] == 3 && nums[1] == 3)
            return true
        else
		return (nums[0] == 5 && nums[1] == 5)
		end
	return false
	end
	end
print check_array([3, 3]),"\n" 
print check_array([3, 6]),"\n" 
print check_array([5, 9]),"\n" 
print check_array([5, 5]),"\n"   
print check_array([8, 9])

Output:

true
false
false
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