Scala Int until(end: Int, step: Int) 方法与示例
until(end: Int, step: Int)方法用于返回从起始值到指定结束整数值的精确先前值的范围。这里范围的值按步长跳跃。
Method Definition: defuntil(end: Int, step: Int): collection.immutable.Range
Return Type: It returns the range.
示例 #1:
// Scala program of Int until()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying until method
val result = (10).until(17, 2)
// Displays output
println(result)
}
}
输出:
Range(10, 12, 14, 16)
示例 #2:
// Scala program of Int until()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying until method
val result = (1).until(12, 3)
// Displays output
println(result)
}
}
输出:
Range(1, 4, 7, 10)