Q:

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

0

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

All Answers

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

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

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