📜  Scala Int toShort() 方法与示例

📅  最后修改于: 2022-05-13 01:54:53.164000             🧑  作者: Mango

Scala Int toShort() 方法与示例

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

方法定义: (Number).toShort
返回类型:它返回转换后的短数据类型值。

示例 1:

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


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


输出:
1

示例 2:

斯卡拉

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