Write a Scala program to check whether two given integers are in the range 40..50 inclusive, or they are both in the range 50..60 inclusive.
object scala_basic { def test(x: Int, y: Int): Boolean = { List(x, y).forall { m => m >= 40 && m <= 50 } || List(x, y).forall { n => n >= 50 && n <= 60 } } def main(args: Array[String]): Unit = { println("Result: " + test(78,95)); println("Result: " + test(25,35)); println("Result: " + test(40,50)); println("Result: " + test(55,60)); } }
Sample Output:
Result: false Result: false Result: true Result: true
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer