Skip to content
Related Articles

Related Articles

Scala Int toShort() method with example
  • Last Updated : 23 Feb, 2021
GeeksforGeeks - Summer Carnival Banner

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

 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :