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