Q:

Write a Scala program to check a given integer and return true if it is within 20 of 100 or 300

0

Write a Scala program to check a given integer and return true if it is within 20 of 100 or 300.

All Answers

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

object scala_basic {
  def test(x:Int) : Boolean  =
    {
     Math.abs(100 - x) <= 20 || Math.abs(300 - x) <= 20
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(115));
      println("Result: " + test(200));
      println("Result: " + test(250));
      println("Result: " + test(70));
   }
}

Sample Output:

Result: true
Result: false
Result: false
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