Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Ruby Basic Exercises: Check two temperatures

Ruby Basic: Exercise-25 with Solution

Write a Ruby program to check two temperatures and return true if one is less than 0 and the other is greater than 100.

Ruby Code:

def temp(temp1, temp2)
    return ( temp1 < 0 && temp2 > 100 ) || ( temp1 > 100 && temp2 < 0 );
end
print temp(110, -1),"\n"
print temp(-1, 110),"\n"
print temp(2, 120)

Output:

true
true
false

Flowchart:

Flowchart: Check two temperatures

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to create a new string from a given string with the last character added at the front and back of the given string. The lenght of the given string must be 1 or more.
Next: Write a Ruby program to print 34 upto 41.

What is the difficulty level of this exercise?