Scala Programming: Create a new string which is n copies of a given string
Scala Programming Basic Exercise-26 with Solution
Write a Scala program to create a new string which is n (non-negative integer ) copies of a given string.
Sample Solution:
Scala Code:
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
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework