Q:

Write a Scala program to create a new string which is n (non-negative integer ) copies of a given string

0

Write a Scala program to create a new string which is n (non-negative integer ) copies of a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now