Repeat the given string exactly n times

To repeat a given string n times in Scala, you can use the String's * operator. Here's an example:

val str = "Hello"
val n = 3
val repeatedString = str * n


This will output:


In the example above, the * operator is used to multiply the string str by n. This results in the string being repeated n times and assigned to the repeatedString variable.