Write a Scala program to check whether three given integer values are in the range 20..50 inclusive. Return true if 1 or more of them are in the said range otherwise false

  • برمجة سكالا

Write a Scala program to check whether three given integer values are in the range 20..50 inclusive. Return true if 1 or more of them are in the said range otherwise false.

الأجوبة

object scala_basic {
  def test(x: Int, y: Int, z: Int): Boolean = 
    {
      (x >= 20 && x <= 50) || (y >= 20 && y <= 50) || (z >= 20 && z <= 50);
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(11, 20, 12));
      println("Result: " + test(30, 30, 17));
      println("Result: " + test(25, 35, 50));
      println("Result: " + test(15, 12, 8));
    }
}

Sample Output:

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

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

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

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