Scala Int to(end: Int) method with example
Last Updated :
30 Jan, 2020
The to(end: Int) method is utilized to return a range from the stated int to the ‘end’, which is given in the arguments list but here “step” is not specified in the arguments list.
Method Definition: def to(end: Int): Inclusive
Return Type: It returns the range.
Example #1:
object GfG
{
def main(args : Array[String])
{
val result = 5 .to( 10 )
println(result)
}
}
|
Output:
Range(5, 6, 7, 8, 9, 10)
Example #2:
object GfG
{
def main(args : Array[String])
{
val result = 20 .to( 25 )
println(result)
}
}
|
Output:
Range(20, 21, 22, 23, 24, 25)
Share your thoughts in the comments
Please Login to comment...