Write a Scala program to check whether two given integers are in the range 40..50 inclusive, or they are both in the range 50..60 inclusive

  • برمجة سكالا

Write a Scala program to check whether two given integers are in the range 40..50 inclusive, or they are both in the range 50..60 inclusive.

الأجوبة

object scala_basic {
  def test(x: Int, y: Int): Boolean = {
     List(x, y).forall { m => m >= 40 && m <= 50 } || List(x, y).forall { n => n >= 50 && n <= 60 }
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(78,95));
      println("Result: " + test(25,35));
      println("Result: " + test(40,50));      
      println("Result: " + test(55,60));      
    }
  }

Sample Output:

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

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

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

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