Q:

Write a Scala program to get the absolute difference between n and 51. If n is greater than 51 return triple the absolute difference

0

Write a Scala program to get the absolute difference between n and 51. If n is greater than 51 return triple the absolute difference.

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) : Int =
    {
    val abs_Diff = Math.abs(x - 51)
    if (x > 51) 3 * abs_Diff else abs_Diff
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(60));
      println("Result: " + test(40));
   }
}

Sample Output:

Result: 27
Result: 11

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