object Scala_String {
def test(stng: String): String = {
val l = stng.length;
var newstring = "";
for (i <- 0 to l - 1) {
newstring += stng.substring(i, i + 1) + stng.substring(i, i + 1);
}
newstring;
}
def main(args: Array[String]): Unit = {
val str1 = "welcome";
println("The given string is: " + str1);
println("The new string is: " + test(str1));
}
}
Sample Output:
The given string is: welcome
The new string is: wweellccoommee
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer