to(end:FLoat,step:Float)方法用於返回從聲明的float值到“ end”的範圍,該範圍在參數列表中給出,並且在參數列表中也指定了某個步驟。
函數定義: def to(end:Float, step:Float):Inclusive
返回類型: It returns the range.
範例1:
// Scala program of Float to()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying to() method
val result = (0.0).to(9.0, 4.0)
// Displays output
println(result)
}
}
輸出:
NumericRange(0.0, 4.0, 8.0)
範例2:
// Scala program of Float to()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying to() method
val result = (5.0).to(30.0, 4.0)
// Displays output
println(result)
}
}
輸出:
NumericRange(5.0, 9.0, 13.0, 17.0, 21.0, 25.0, 29.0)
相關用法
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Scala Float to(end: Float, step: Float) method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。