Write a Scala program to create a new string which is n (non-negative integer ) copies of a given string.
object scala_basic { def test(str1: String, n: Int): String = { str1 * n; } def main(args: Array[String]): Unit = { println("Result: " + test("Scala", 2)); println("Result: " + test("Python",1)); println("Result: " + test("JS",6)); } }
Sample Output:
Result: ScalaScala Result: Python Result: JSJSJSJSJSJS
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer