Write a Ruby program to check whether it contains no 3 or it contains no 5.
def check_array(nums) noThree = true, noFive = true; i = 0; while i < nums.length && (noThree || noFive) if(nums[i] == 3) noThree = false elsif(nums[i] == 5) noFive = false end i = i + 1 end return (noThree || noFive) end print check_array([3, 7, 3, 3]),"\n" print check_array([2, 8, 2, 9]),"\n" print check_array([3, 8, 5, 9]),"\n"
Output:
true [true, true] false
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer