Write a Scala program to compute the sum of the two given integer values. If the two values are the same, then return triples their sum

  • برمجة سكالا

Write a Scala program to compute the sum of the two given integer values. If the two values are the same, then return triples their sum.

الأجوبة

object scala_basic {
  def test(x:Int, y:Int) : Int =
    {
        if (x == y) (x + y) * 3 else x + y
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(1, 2));
      println("Result: " + test(2, 2));
   }
}

Sample Output:

Result: 3
Result: 12
هل كان المحتوى مفيد؟

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

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

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