Scala Float until(end: Float, step: Float) 方法与示例
until(end: Float, step: Float)方法用于返回从起始值到指定结束浮点值的精确先前值的范围。这里范围的值按步长跳跃。
Method Definition: defuntil(end: Float, step: Float): collection.immutable.Range
Return Type: It returns the range.
示例 #1:
// Scala program of Float until()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying until method
val result = (1.0).until(12.0, 3.0)
// Displays output
println(result)
}
}
输出:
NumericRange(1.0, 4.0, 7.0, 10.0)
示例 #2:
// Scala program of Float until()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying until method
val result = (3.0).until(20.0, 2.0)
// Displays output
println(result)
}
}
输出:
NumericRange(3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0, 17.0, 19.0)