Q:

Write a Ruby program to check two integers and return true if one of them is 20 otherwise return their sum

0

Write a Ruby program to check two integers and return true if one of them is 20 otherwise return their sum.

All Answers

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

Ruby Code:

def makes20(x,y)
    return x == 20 || y == 20 || x + y == 20
end

print makes20(10, 10),"\n" 
print makes20(40, 10),"\n" 
print makes20(15, 20)
Output:
true
false
true

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