Write a Scala program to check whether a given positive number is a multiple of 3 or a multiple of 7

  • برمجة سكالا

Write a Scala program to check whether a given positive number is a multiple of 3 or a multiple of 7.

الأجوبة

object scala_basic {
  def test(n: Int): Boolean = 
    {
    n % 3 == 0 || n % 7 == 0;
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(3));
      println("Result: " + test(14));
      println("Result: " + test(12));
      println("Result: " + test(37));
    }
}

Sample Output:

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

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

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

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