Write a Scala program to create a new string which is 4 copies of the 2 front characters of a given string.If the given string length is less than 2 return the original string
- برمجة سكالا
- 2021-09-23
- mhanasmh00489829403
الأجوبة
object scala_basic {
def test(str1: String): String =
{
if (str1.length < 2) str1
else str1.substring(0, 2) * 4
}
def main(args: Array[String]): Unit = {
println("Result: " + test("Scala"));
println("Result: " + test("abcd"));
println("Result: " + test("ab"));
println("Result: " + test("a"));
}
}
Sample Output:
Result: ScScScSc Result: abababab Result: abababab Result: a
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة