w3resource

Scala Programming: Check whether one of the given temperatures is less than 0 and the other is greater than 100

Scala Programming Basic Exercise-14 with Solution

Write a Scala program to check whether one of the given temperatures is less than 0 and the other is greater than 100.

Sample Solution:

Scala Code:

object scala_basic {
  def test(temp1: Int, temp2: Int): Boolean = 
    {
      (temp1 < 0 && temp2 > 100) || (temp2 < 0 && temp1 > 100)
    }     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(120, -1));
      println("Result: " + test(-1, 120));
      println("Result: " + test(2, 120));
    }
}

Sample Output:

Result: true
Result: true
Result: false

Scala Code Editor :

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Scala program to check whether a given string starts with 'Sc' or not.
Next: Write a Scala program to check two given integers whether either of them is in the range 100..200 inclusive.

What is the difficulty level of this exercise?