Write a Scala program to check whether one of the given temperatures is less than 0 and the other is greater than 100

  • برمجة سكالا

Write a Scala program to check whether one of the given temperatures is less than 0 and the other is greater than 100.

الأجوبة

Scala Code:

object scala_basic {
  def test(temp1: Int, temp2: Int): Boolean = 
    {
      (temp1 < 0 && temp2 > 100) || (temp2 < 0 && temp1 > 100)
    }     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(120, -1));
      println("Result: " + test(-1, 120));
      println("Result: " + test(2, 120));
    }
}
Sample Output:
Result: true
Result: true
Result: false
هل كان المحتوى مفيد؟

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

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

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