object SeqCreateAndInitialize {
def main(args: Array[String]): Unit = {
// Creates a sequence of numbers within a range.
val rangeSeq = Seq.range(1, 10, 2) // List(1, 3, 5, 7, 9)
// 1. Print the whole sequence directly
println(rangeSeq)
// 2. Print elements separated by spaces
println(rangeSeq.mkString(" "))
// 3. Print elements with custom formatting
println(rangeSeq.mkString("[", ", ", "]"))
// 4. Iterate and print each element
rangeSeq.foreach(println)
}
}
/*
run:
NumericRange 1 until 10 by 2
1 3 5 7 9
[1, 3, 5, 7, 9]
1
3
5
7
9
*/