Write a Scala program to create a new string where 'if' is added to the front of a given string. If the string already begins with 'if', return the string unchanged
- برمجة سكالا
- 2021-09-23
- mhanasmh00489829403
الأجوبة
object scala_basic {
def test(str: String): String =
{
if (str.startsWith("if")) str else "if " + str
}
def main(args: Array[String]): Unit = {
println("Result: " + test("if else"));
println("Result: " + test("else"));
}
}
Sample Output:
Result: if else Result: if else
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة