当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala Int toShort()用法及代码示例


toShort()方法用于将指定的int数转换为short类型值。

函数定义: (Number).toShort

返回类型: It returns the converted short datatype value.



范例1:

// Scala program of Int toLong() 
// method 
  
// Creating object 
object GfG 
{  
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Applying toShort method 
        val result = (1).toShort 
          
          
        // Displays output 
        println(result) 
    } 
} 
输出:
1

范例2:

// Scala program of Int toLong() 
// method 
  
// Creating object 
object GfG 
{  
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Applying toShort method 
        val result = (187449572).toShort 
          
        // Displays output 
        println(result) 
    } 
} 
输出:
16612


相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Scala Int toShort() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。