Write a Scala program to check whether a given character presents in a string between 2 to 4 times
- برمجة سكالا
- 2021-09-23
- mhanasmh00489829403
الأجوبة
object scala_basic {
def test(str1: String): Boolean = {
val count_char = str1.count{ n => n == 'z' }
count_char >= 2 && count_char <= 4
}
def main(args: Array[String]): Unit = {
println("Result: " + test("frizz"));
println("Result: " + test("zane"));
println("Result: " + test("Zazz"));
println("Result: " + test("false"));
}
}
Sample Output:
Result: true Result: false Result: true Result: false
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة