Write a Scala program to check a given integer and return true if it is within 20 of 100 or 300.
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
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