Write a Scala program to get the absolute difference between n and 51. If n is greater than 51 return triple the absolute difference.
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
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