Write a Scala program to find the larger value from two positive integer values in the range 20..30 inclusive, or return 0 if neither is in that range
- برمجة سكالا
- 2021-09-23
- mhanasmh00489829403
الأجوبة
object scala_basic {
def test(x: Int, y: Int): Int = {
val max_of_two = List(x, y).max
if (max_of_two >= 20 && max_of_two <= 30) max_of_two else 0
}
def main(args: Array[String]): Unit = {
println("Result: " + test(78,95));
println("Result: " + test(20,30));
println("Result: " + test(21,25));
println("Result: " + test(28,28));
}
}
Sample Output:
Result: 0 Result: 30 Result: 25 Result: 28
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة