Write a Scala program to check whether a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string
- برمجة سكالا
- 2021-09-23
- mhanasmh00489829403
الأجوبة
object scala_basic {
def test(str: String): String = {
if (str.drop(1).startsWith("yt")) str.replaceFirst("yt", "")
else str
}
def main(args: Array[String]): Unit = {
println("Result: " + test("Scala"));
println("Result: " + test("yytade"));
println("Result: " + test("ytsues"));
}
}
Sample Output:
Result: Scala Result: yade Result: ytsues
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة