Open In App

Scala Int toShort() method with example

Last Updated : 23 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The toShort() method is utilized to convert the specified int number into a short type value.
 

Method Definition: (Number).toShort
Return Type: It returns the converted short datatype value. 

Example 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)
    }
}


Output: 

1

 

Example 2: 

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)
    }
}


Output: 

16612

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads