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

  • برمجة سكالا

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
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...