Write a Scala program to create a new string with the last char added at the front and back of a given string of length 1 or more
- برمجة سكالا
- 2021-09-23
- mhanasmh00489829403
الأجوبة
object scala_basic {
def test(str1: String): String =
{
val len = str1.length
val last = str1.charAt(len - 1)
last + str1 + last
}
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: aScalaa Result: dabcdd Result: babb Result: aaa
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة