Scala StringOps.*
Repeat a short display token to build a three-place progress indicator.
A simple example
StringOps.*
- Start with "a", count 3
- Do this Repeat the text
- Result "aaa"
object Lesson {
def main(args: Array[String]): Unit = {
val value = "a"
println(value * 3)
}
}
aaa
Syntax
value * 3
Run these examples in Scala
Save one example at a time as Lesson.scala. Use Scala 2.13 on JDK 21.
scalac Lesson.scala
scala LessonDraw three completed checkpoints
A progress display shows one mark for each completed checkpoint. Generate the three marks from the completion count so the same code can display another count later.
object Lesson {
def main(args: Array[String]): Unit = {
val value = "+"
println(value * 3)
}
}
+++
Each plus sign stands for one completed step.
Mark three empty seats
A small text-only display uses a repeated mark to represent a divider or a count. Generate the marks from the requested number so the visual result grows or shrinks with the input.
object Lesson {
def main(args: Array[String]): Unit = {
val value = "[]"
println(value * 3)
}
}
[][][]
The whole two-character token is repeated three times.
Mark a workshop attendance card
A student attends three workshop sessions. The card printer repeats one mark for every earned stamp. What strip appears on the card?
What to watch for
Set a sensible upper bound before repeating text according to user input.