Write a Scala program to get the absolute difference between n and 51. If n is greater than 51 return triple the absolute difference
- برمجة سكالا
- 2021-09-23
- mhanasmh00489829403
الأجوبة
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
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة