Write a Scala program to check two given integers, and return true if one of them is 30 or if their sum is 30

  • برمجة سكالا

Write a Scala program to check two given integers, and return true if one of them is 30 or if their sum is 30.

 

الأجوبة

object scala_basic {
  def test(x:Int, y:Int) : Boolean  =
    {
     x == 30 || y == 30 || x + y == 30
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(30, 0));
      println("Result: " + test(25, 5));
      println("Result: " + test(30, 20));
      println("Result: " + test(25, 20));
   }
}

Sample Output:

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

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

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

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