Scala Int until(end: Int) 方法与示例
until(end: Int)方法用于返回从起始值到指定结束整数值的精确先前值的范围。
Method Definition: defuntil(end: 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 = (1).until(9)
// Displays output
println(result)
}
}
输出:
Range(1, 2, 3, 4, 5, 6, 7, 8)
示例 #2:
// 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)
// Displays output
println(result)
}
}
输出:
Range(10, 11, 12, 13, 14, 15, 16)