Scala Int to(end: int, step: int) 方法与示例
to(end: int, step: int)方法用于返回从指定整数到“end”的范围,该范围在参数列表中给出,并且在参数列表中还指定了一些步骤。
Method Definition: def to(end: Int, step: Int): Inclusive
Return Type: It returns the range.
示例 #1:
// Scala program of Int to()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying to() method
val result = 5.to(10, 2)
// Displays output
println(result)
}
}
输出:
Range(5, 7, 9)
示例 #2:
// Scala program of Int to()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying to() method
val result = (0).to(9, 3)
// Displays output
println(result)
}
}
输出:
Range(0, 3, 6, 9)