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

Scala Programming: Check two given integers whether either of them is in the range 100..200 inclusive

Scala Programming Basic Exercise-15 with Solution

Write a Scala program to check two given integers whether either of them is in the range 100..200 inclusive.

Sample Solution:

Scala Code:

object scala_basic {
  def test(x: Int, y: Int): Boolean = 
    {
      (x >= 100 && x <= 200) || (y >= 100 && y <= 200);
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(100, 199));
      println("Result: " + test(250, 300));
      println("Result: " + test(105, 190));
    }
}

Sample Output:

Result: true
Result: false
Result: true

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 one of the given temperatures is less than 0 and the other is greater than 100.
Next: Write a Scala program to check whether three given integer values are in the range 20..50 inclusive. Return true if 1 or more of them are in the said range otherwise false.

What is the difficulty level of this exercise?