to(end:int,step:int)方法用于返回从指定整数到“ end”的范围,该范围在参数列表中给出,并且在参数列表中也指定了某个步骤。
函数定义: def to(end:Int, step:Int):Inclusive
返回类型: 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)
相关用法
- Scala Int until(end: Int, step: Int)用法及代码示例
- Scala Float to(end: Float, step: Float)用法及代码示例
- Scala Float until(end: Float, step: Float)用法及代码示例
- Scala Char to(end: Char, step: Char)用法及代码示例
- Scala Int abs()用法及代码示例
- Scala Set min()用法及代码示例
- Scala Set &~()用法及代码示例
- Scala map()用法及代码示例
- Scala Map take()用法及代码示例
- Scala Map get()用法及代码示例
- Scala Set contains()用法及代码示例
- Scala Set ++()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Scala Int to(end: int, step: int) method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
